Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
1 lines (1 loc) · 1.63 KB
/
Copy pathmain.js
File metadata and controls
1 lines (1 loc) · 1.63 KB
1
define(function(require,exports,module){var EditorManager=brackets.getModule("editor/EditorManager"),ExtensionUtils=brackets.getModule("utils/ExtensionUtils"),ProjectManager=brackets.getModule("project/ProjectManager"),InlineImageViewer=require("InlineImageViewer");function _getStringAtPos(hostEditor,pos){var token=hostEditor._codeMirror.getTokenAt(pos,!0);if(/\S/.test(token.string)&&"."!==token.string||(token=hostEditor._codeMirror.getTokenAt({line:pos.line,ch:pos.ch+1},!0)),"string"===token.type){var string=token.string,ch=string[0];return'"'!==ch&&"'"!==ch||(string=string.substr(1)),'"'!==(ch=string[string.length-1])&&"'"!==ch||(string=string.substr(0,string.length-1)),string}var line=hostEditor._codeMirror.getLine(pos.line),match=/url\s*\(([^)]*)\)/.exec(line);if(match&&match[1]){var docPath=hostEditor.document.file.fullPath;return(docPath=docPath.substr(0,docPath.lastIndexOf("/")))+"/"+match[1]}return""}function inlineImageViewerProvider(hostEditor,pos){var sel=hostEditor.getSelection(!1);if(sel.start.line!==sel.end.line)return null;var fileName=_getStringAtPos(hostEditor,hostEditor.getSelection(!1).start);if(""===fileName)return null;if(!/(\.png|\.jpg|\.jpeg|\.gif|\.webp|\.svg)$/i.test(fileName))return null;var projectPath=ProjectManager.getProjectRoot().fullPath;0!==fileName.indexOf(projectPath)&&(fileName=projectPath+fileName);var result=new $.Deferred,imageViewer=new InlineImageViewer(fileName.substr(fileName.lastIndexOf("/")),fileName);return imageViewer.load(hostEditor),result.resolve(imageViewer),result.promise()}ExtensionUtils.loadStyleSheet(module,"style.css"),EditorManager.registerInlineEditProvider(inlineImageViewerProvider)});