Skip to content

Commit baec93f

Browse files
committed
Fix content being cut off at space for multiline ops
1 parent 1d2fac9 commit baec93f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,10 @@ function wordSelectionStart(text: string, i: number): number {
256256
return index
257257
}
258258

259-
function wordSelectionEnd(text: string, i: number): number {
259+
function wordSelectionEnd(text: string, i: number, multiline: boolean): number {
260260
let index = i
261-
while (text[index] && !text[index].match(/\s/)) {
261+
const breakPoint = multiline ? /\n/ : /\s/
262+
while (text[index] && !text[index].match(breakPoint)) {
262263
index++
263264
}
264265
return index
@@ -322,10 +323,15 @@ function styleSelectedText(textarea: HTMLTextAreaElement, styleArgs: StyleArgs)
322323
insertText(textarea, result)
323324
}
324325

325-
function expandSelectedText(textarea: HTMLTextAreaElement, prefixToUse: string, suffixToUse: string): string {
326+
function expandSelectedText(
327+
textarea: HTMLTextAreaElement,
328+
prefixToUse: string,
329+
suffixToUse: string,
330+
multiline: boolean = false
331+
): string {
326332
if (textarea.selectionStart === textarea.selectionEnd) {
327333
textarea.selectionStart = wordSelectionStart(textarea.value, textarea.selectionStart)
328-
textarea.selectionEnd = wordSelectionEnd(textarea.value, textarea.selectionEnd)
334+
textarea.selectionEnd = wordSelectionEnd(textarea.value, textarea.selectionEnd, multiline)
329335
} else {
330336
const expandedSelectionStart = textarea.selectionStart - prefixToUse.length
331337
const expandedSelectionEnd = textarea.selectionEnd + suffixToUse.length
@@ -399,7 +405,7 @@ function blockStyle(textarea: HTMLTextAreaElement, arg: StyleArgs): SelectionRan
399405
prefixToUse = ` ${prefixToUse}`
400406
}
401407
}
402-
selectedText = expandSelectedText(textarea, prefixToUse, suffixToUse)
408+
selectedText = expandSelectedText(textarea, prefixToUse, suffixToUse, arg.multiline)
403409
let selectionStart = textarea.selectionStart
404410
let selectionEnd = textarea.selectionEnd
405411
const hasReplaceNext = replaceNext.length > 0 && suffixToUse.indexOf(replaceNext) > -1 && selectedText.length > 0

0 commit comments

Comments
 (0)