Skip to content

Commit e7fdc97

Browse files
authored
fix broken arrow navigation on wrapped lines (#170)
1 parent 70bf0f1 commit e7fdc97

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/cm_adapter.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,18 +272,19 @@ export class CodeMirror {
272272
setSelections(p: CM5RangeInterface[], primIndex?: number) {
273273
var doc = this.cm6.state.doc
274274
var ranges = p.map(x => {
275-
return EditorSelection.range(indexFromPos(doc, x.anchor), indexFromPos(doc, x.head))
275+
var head = indexFromPos(doc, x.head)
276+
var anchor = indexFromPos(doc, x.anchor)
277+
// workaround for codemirror bug, see https://github.com/replit/codemirror-vim/issues/169
278+
if (head == anchor)
279+
return EditorSelection.cursor(head, 1)
280+
return EditorSelection.range(anchor, head)
276281
})
277282
this.cm6.dispatch({
278283
selection: EditorSelection.create(ranges, primIndex)
279284
})
280285
};
281286
setSelection(anchor: Pos, head: Pos, options?: any) {
282-
var doc = this.cm6.state.doc
283-
var ranges = [EditorSelection.range(indexFromPos(doc, anchor), indexFromPos(doc, head))]
284-
this.cm6.dispatch({
285-
selection: EditorSelection.create(ranges, 0)
286-
})
287+
this.setSelections([{anchor, head}], 0);
287288
if (options && options.origin == '*mouse') {
288289
this.onBeforeEndOperation();
289290
}
@@ -539,7 +540,7 @@ export class CodeMirror {
539540
let pixels = unit == 'page' ? cm6.dom.clientHeight : 0;
540541

541542
const startOffset = indexFromPos(doc, start);
542-
let range = EditorSelection.range(startOffset, startOffset, goalColumn);
543+
let range = EditorSelection.cursor(startOffset, 1, undefined, goalColumn);
543544
let count = Math.round(Math.abs(amount))
544545
for (let i = 0; i < count; i++) {
545546
if (unit == 'page') {

0 commit comments

Comments
 (0)