File tree Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -246,14 +246,25 @@ jQuery(function () {
246
246
if ( ! $editarea . length ) {
247
247
return ;
248
248
}
249
- var syntax = '{{' + fileid + '}}' ;
250
- var caretPos = $editarea [ 0 ] . selectionStart ;
251
- var prefix = $editarea . text ( ) . substring ( 0 , caretPos ) ;
252
- var postfix = $editarea . text ( ) . substring ( caretPos ) ;
253
- $editarea . text ( prefix + syntax + postfix ) ;
254
- var newCaretPos = caretPos + syntax . length ;
255
- $editarea [ 0 ] . setSelectionRange ( newCaretPos , newCaretPos ) ;
256
- $lastKnownCaretPosition = newCaretPos ; // IE 11 fix
249
+ var open = '{{' + fileid ;
250
+ var close = '}}' ;
251
+
252
+ var selection = DWgetSelection ( $editarea [ 0 ] ) ;
253
+ var text = selection . getText ( ) ;
254
+ var opts ;
255
+
256
+ // don't include trailing space in selection
257
+ if ( text . charAt ( text . length - 1 ) == ' ' ) {
258
+ selection . end -- ;
259
+ text = selection . getText ( ) ;
260
+ }
261
+
262
+ if ( text ) {
263
+ text = '|' + text ; // use text as label
264
+ }
265
+ opts = { nosel : true } ;
266
+ text = open + text + close ;
267
+ pasteText ( selection , text , opts ) ;
257
268
}
258
269
259
270
/**
You can’t perform that action at this time.
0 commit comments