-
Notifications
You must be signed in to change notification settings - Fork 30
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
Block cursor improvements #82
base: master
Are you sure you want to change the base?
Conversation
I've simplified the implementation of The inconsistency between the heights of the block cursor on empty and non-empty lines is still something I think should be fixed; I could try to find another way if you prefer. |
On which version of codemirror do you see cursor height changing on empty line, i don't see it with @codemirror/[email protected]. I am not completely sure, but I think changing the way character height is calculated only for block cursor is not a good approach. It adds more problems like not having good solution for widgets, your screenshot, the text cursor being one pixel higher than what it should be in some cases If one wants both cursor and selection to be of defaultLineHeight, wouldn't it be simpler to override coordsAtPos method, like this? if (!_view.__proto__.coordsAtPos0) _view.__proto__.coordsAtPos0 = _view.__proto__.coordsAtPos
_view.__proto__.coordsAtPos = function(pos, side) {
const coords = this.coordsAtPos0(pos, side);
if (!coords) {
return null;
}
const halfLeading =
(this.defaultLineHeight - (coords.bottom - coords.top)) / 2;
return {
left: coords.left,
right: coords.right,
top: coords.top - halfLeading,
bottom: coords.bottom + halfLeading,
};
} The change for transparent color looks good. |
I'm seeing it on
Yeah, I think I agree. I'm not sure what the answer is though. I'll give it some more thought.
Great. I've made a new PR with just that part: #89 |
Why
The block cursor currently has a couple of issues.
Firstly, the cursor is taller on an empty line than on non-empty lines. To illustrate this, all of the following screenshots use
line-height: 2.5
.Non-empty line:
Empty line:
Secondly, an unfocused cursor overlays a copy of the character such that both are visible, making the character look stronger:
What changed
For the first issue, I've added a
fullHeightCoordsAtPos
function, which acts likecoordsAtPos
except that the top and bottom coordinates represent the top and bottom of the whole visual line, not just the text. It also works with wrapped lines. However, in order to work with wrapped lines, it relies on the assumption that every visual line within the wrapped line has the same height, which is not necessarily the case if the line contains widgets or decorations that affect the height of the line.For the second issue, I've made the colour of the content of an unfocused block cursor transparent:
Test plan
dev/index.ts
:EditorView.baseTheme({ '.cm-line': { lineHeight: '2.5' } })