Skip to content

Commit cbeb9b7

Browse files
committed
Extract an insertQuote function
1 parent d6dca6b commit cbeb9b7

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

quote-selection.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,7 @@ export function quote(text: string, range: Range): boolean {
9292
const field = findTextarea(container)
9393
if (!field) return false
9494

95-
let quotedText = `> ${selectionText.replace(/\n/g, '\n> ')}\n\n`
96-
if (field.value) {
97-
quotedText = `${field.value}\n\n${quotedText}`
98-
}
99-
field.value = quotedText
100-
field.focus()
101-
field.selectionStart = field.value.length
102-
field.scrollTop = field.scrollHeight
103-
95+
insertQuote(selectionText, field)
10496
return true
10597
}
10698

@@ -138,6 +130,17 @@ function extractQuote(text: string, range: Range): ?Quote {
138130
return {selectionText, container}
139131
}
140132

133+
function insertQuote(selectionText: string, field: HTMLTextAreaElement) {
134+
let quotedText = `> ${selectionText.replace(/\n/g, '\n> ')}\n\n`
135+
if (field.value) {
136+
quotedText = `${field.value}\n\n${quotedText}`
137+
}
138+
field.value = quotedText
139+
field.focus()
140+
field.selectionStart = field.value.length
141+
field.scrollTop = field.scrollHeight
142+
}
143+
141144
function visible(el: HTMLElement): boolean {
142145
return !(el.offsetWidth <= 0 && el.offsetHeight <= 0)
143146
}

0 commit comments

Comments
 (0)