-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Indentation issue when using tabs and tabSize
#2
Comments
Hi @josdejong thank you for reporting this. I see that there are 2 issues causing this: First, the function Second, Do you already have workaround at your end? maybe have option to disable this extension? If not, I can help with that |
Thanks for looking into it! I don't have a workaround yet, but it is only an esthetic problem so no showstopper. As a workaround I could for example disable disable |
I did some testing, and it looks like this will be solved by just fixing getIndentSize(line) {
return (line.text.length - line.text.trimStart().length) * tabSize;
} Now, of course the method needs to check whether the indentation is tabs and only then multiply with the actual tabSize, but besides that all seems to work fine. |
@josdejong thank you for trying it out. I tried to implement it. But I still see that the issue still persists. https://stackblitz.com/edit/codemirror-wrapped-line-indent-issue-with-tabs-jrekfw?file=main.js |
Isn't that because |
hmm, I don't think so, because the doc is still using |
If you mix config and actual indentation, things will always look weird. I think you shouldn't mix it:
I was testing with something like this: import { basicSetup, EditorView } from "codemirror";
import { EditorState } from '@codemirror/state';
import { indentUnit } from '@codemirror/language';
import { wrappedLineIndent } from "../src/index";
const indentation = ' ' // 4 spaces
// const indentation = '\t' // tab
const tabSize = 8;
const data = {
"deep": {
"nested": {
"value": "verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyylooooooooooooonnggg"
}
}
}
const doc = JSON.stringify(data, null, indentation)
const editor = new EditorView({
doc,
extensions: [
basicSetup,
EditorState.tabSize.of(tabSize),
indentUnit.of(indentation),
wrappedLineIndent
],
parent: document.getElementById("app")!,
}); |
That's actually a nice constraint. I have published the fix that can works with https://stackblitz.com/edit/codemirror-wrapped-line-indent-issue-with-tabs-jrekfw?file=main.js I will update again when I found how to fix it for chrome |
Thanks! |
I've now updated to v1.0.5 and have been doing testing in both Firefox and Chrome, but I can't reproduce an issue anymore 🤔. Do you still have a case that fails in Chrome? |
@josdejong I see the issue on both browser 🥲 I modified the parser a little so it add indent with |
Ahh, yes. So to reproduce:
|
@josdejong I applied browser engine detection to do different calculation on the text-indent value. It looks good so far, could you try it at your end. the version is 1.0.8 |
Thanks for working on a fix! It's unfortunate if there is a switch for different browsers needed. I had hoped we had that time behind us now that IE is retired 😅. I did some testing on Firefox, Chrome, and Edge (wasn't able to test on Safari). On Chrome and Edge there still is some flaky behavior, see the following gif: |
I came across an issue when using a document indented with tabs: the first indentation level doesn't respect the configured
tabSize
when usingcodemirror-wrapped-line-indent
You can try it out in this demo: https://stackblitz.com/edit/codemirror-wrapped-line-indent-issue-with-tabs?file=main.js&terminal=dev
Basically:
With
codemirror-wrapped-line-indent
enabled, the first indentation level is wrong:When disabling the extension, the indentation is correct:
The text was updated successfully, but these errors were encountered: