File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ const lTools = require ( '../tools/LinkTools' )
2
+ const eTools = require ( '../tools/EditorTools' )
3
+
4
+ const vscode = require ( 'vscode' )
5
+ const Window = vscode . window
6
+
7
+ const handleEmptySelection = ( ) => { return false }
8
+
9
+ module . exports = ( ) => {
10
+ try {
11
+ let editor = Window . activeTextEditor
12
+ let selection = editor . selection
13
+ if ( selection . isEmpty ) handleEmptySelection ( )
14
+
15
+ lTools . getLinkUrl ( Window ) . then ( url => {
16
+ if ( url === undefined || url . length === 0 ) return
17
+
18
+ lTools . getNewReference ( url , editor . document ) . then ( newLink => {
19
+ eTools . insertImageReferenceText ( selection , newLink ) . then ( res => {
20
+ if ( ! newLink . existed ) eTools . insertReferenceToFile ( newLink )
21
+ } ) . catch ( err => Window . showErrorMessage ( err . message ) )
22
+ } ) . catch ( err => Window . showErrorMessage ( err . message ) )
23
+ } ) . catch ( err => Window . showErrorMessage ( err . message ) )
24
+ } catch ( error ) {
25
+ console . log ( error )
26
+ }
27
+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ exports.activate = () => {
4
4
console . log ( `Enmeti has been activated.` )
5
5
6
6
vscode . commands . registerCommand ( 'enmeti.insertLink' , require ( './cmds/InsertLink' ) )
7
+ vscode . commands . registerCommand ( 'enmeti.insertImage' , require ( './cmds/InsertImage' ) )
7
8
}
8
9
9
10
exports . deactivate = ( ) => { }
You can’t perform that action at this time.
0 commit comments