mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 03:06:31 -05:00
Fix insertOnStartOfLines behaviour
A bug in insertOnStartOfLines lead to duplicated text, if the cursor was not at the start of a line. This fixes the behaviour of insertOnStartOfLines to always use the complete first and last line of the selection, even if they were only partially selected. Fixes #1231 Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
f48e36d205
commit
e4b2b6ff73
1 changed files with 7 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
||||||
const wrapSymbols = ['*', '_', '~', '^', '+', '=']
|
const wrapSymbols = ['*', '_', '~', '^', '+', '=']
|
||||||
|
|
||||||
export function wrapTextWith (editor, cm, symbol) {
|
export function wrapTextWith (editor, cm, symbol) {
|
||||||
if (!cm.getSelection()) {
|
if (!cm.getSelection()) {
|
||||||
return CodeMirror.Pass
|
return CodeMirror.Pass
|
||||||
|
@ -106,12 +107,14 @@ export function insertOnStartOfLines (cm, symbol) {
|
||||||
for (let i = 0; i < ranges.length; i++) {
|
for (let i = 0; i < ranges.length; i++) {
|
||||||
const range = ranges[i]
|
const range = ranges[i]
|
||||||
if (!range.empty()) {
|
if (!range.empty()) {
|
||||||
const from = range.from()
|
const cursorFrom = range.from()
|
||||||
const to = range.to()
|
const cursorTo = range.to()
|
||||||
let selection = cm.getRange({ line: from.line, ch: 0 }, to)
|
const firstLineStart = { line: cursorFrom.line, ch: 0 }
|
||||||
|
const lastLineEnd = { line: cursorTo.line, ch: cm.getLine(cursorTo.line).length }
|
||||||
|
let selection = cm.getRange(firstLineStart, lastLineEnd)
|
||||||
selection = selection.replace(/\n/g, '\n' + symbol)
|
selection = selection.replace(/\n/g, '\n' + symbol)
|
||||||
selection = symbol + selection
|
selection = symbol + selection
|
||||||
cm.replaceRange(selection, from, to)
|
cm.replaceRange(selection, firstLineStart, lastLineEnd)
|
||||||
} else {
|
} else {
|
||||||
cm.replaceRange(symbol, { line: cursor.line, ch: 0 }, { line: cursor.line, ch: 0 })
|
cm.replaceRange(symbol, { line: cursor.line, ch: 0 }, { line: cursor.line, ch: 0 })
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue