Skip to content
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

Fix for #3780: Overwrite cursor #3782

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*.swp
.idea
*.iml
/nbproject
9 changes: 8 additions & 1 deletion lib/codemirror.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@
}

/* Can style cursor different in overwrite (non-insert) mode */
.CodeMirror-overwrite .CodeMirror-cursor {}
.CodeMirror-overwrite .CodeMirror-cursor {
width: auto;
background-color: black;
color: white;
border-left: 0;
line-height: normal;
white-space: pre;
}

.cm-tab { display: inline-block; text-decoration: inherit; }

Expand Down
15 changes: 11 additions & 4 deletions lib/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -2321,15 +2321,22 @@
// Draws a cursor for the given range
function drawSelectionCursor(cm, head, output) {
var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine);

var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"));
var content = "\u00a0";
if (cm.state.overwrite) {
var lineObj = getLine(cm.doc, head.line);
var order = getOrder(lineObj);
var part = getBidiPartAt(order, head.ch);
var next = movePos(cm.doc, head, part % 2 ? -1 : 1, 0);
content = next ? (getBetween(cm.doc, part % 2 ? next : head, part % 2 ? head : next)[0] || content) : content;
}
var cursor = output.appendChild(elt("div", content, "CodeMirror-cursor"));
cursor.style.left = pos.left + "px";
cursor.style.top = pos.top + "px";
cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";

if (pos.other) {
// Secondary cursor, shown when on a 'jump' in bi-directional text
var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"));
var otherCursor = output.appendChild(elt("div", content, "CodeMirror-cursor CodeMirror-secondarycursor"));
otherCursor.style.display = "";
otherCursor.style.left = pos.other.left + "px";
otherCursor.style.top = pos.other.top + "px";
Expand Down Expand Up @@ -5241,7 +5248,7 @@
addClass(this.display.cursorDiv, "CodeMirror-overwrite");
else
rmClass(this.display.cursorDiv, "CodeMirror-overwrite");

updateSelection(this);
signal(this, "overwriteToggle", this, this.state.overwrite);
},
hasFocus: function() { return this.display.input.getField() == activeElt(); },
Expand Down