Skip to content

Commit

Permalink
fix: disable wrapped line indent when using tabs because that doesn't…
Browse files Browse the repository at this point in the history
… work well
  • Loading branch information
josdejong committed Mar 13, 2024
1 parent 0860f3e commit 2a067e1
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/lib/components/modes/textmode/TextMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
let validationErrors: ValidationError[] = []
const linterCompartment = new Compartment()
const readOnlyCompartment = new Compartment()
const indentUnitCompartment = new Compartment()
const indentCompartment = new Compartment()
const tabSizeCompartment = new Compartment()
const themeCompartment = new Compartment()
Expand Down Expand Up @@ -606,12 +606,11 @@
search({
top: true
}),
EditorView.lineWrapping,
readOnlyCompartment.of(EditorState.readOnly.of(readOnly)),
tabSizeCompartment.of(EditorState.tabSize.of(tabSize)),
indentUnitCompartment.of(createIndentUnit(indentation)),
themeCompartment.of(EditorView.theme({}, { dark: hasDarkTheme() })),
EditorView.lineWrapping,
wrappedLineIndent
indentCompartment.of(createIndent(indentation)),
themeCompartment.of(EditorView.theme({}, { dark: hasDarkTheme() }))
]
})
Expand Down Expand Up @@ -806,7 +805,7 @@
debug('updateIndentation', indentation)
codeMirrorView.dispatch({
effects: indentUnitCompartment.reconfigure(createIndentUnit(indentation))
effects: indentCompartment.reconfigure(createIndent(indentation))
})
}
}
Expand Down Expand Up @@ -846,8 +845,14 @@
}
}
function createIndentUnit(indentation: number | string): Extension {
return indentUnit.of(typeof indentation === 'number' ? ' '.repeat(indentation) : indentation)
function createIndent(indentation: number | string): Extension[] {
const indent = indentUnit.of(
typeof indentation === 'number' ? ' '.repeat(indentation) : indentation
)
// We disable wrappedLineIndent in case of tabs to work around a bug:
// https://github.com/fauzi9331/codemirror-wrapped-line-indent/issues/2
return indentation === '\t' ? [indent] : [indent, wrappedLineIndent]
}
function updateCanUndoRedo() {
Expand Down

0 comments on commit 2a067e1

Please sign in to comment.