@@ -121,7 +121,7 @@ enum Align {
121121}
122122
123123fn align_view(doc: &Document, view: &mut View, align: Align) {
124− let pos = doc.selection(view.id).cursor();
124+ let pos = doc.selection(view.id).cursor(doc.text().slice(..));
125125 let line = doc.text().char_to_line(pos);
126126
127127 let relative = match align {
@@ -868,7 +868,10 @@ fn switch_to_lowercase(cx: &mut Context) {
868868fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
869869 use Direction::*;
870870 let (view, doc) = current!(cx.editor);
871− let cursor = coords_at_pos(doc.text().slice(..), doc.selection(view.id).cursor());
871+ let cursor = coords_at_pos(
872+ doc.text().slice(..),
873+ doc.selection(view.id).cursor(doc.text().slice(..)),
874+ );
872875 let doc_last_line = doc.text().len_lines() - 1;
873876
874877 let last_line = view.last_line(doc);
@@ -1038,7 +1041,7 @@ fn split_selection_on_newline(cx: &mut Context) {
10381041fn search_impl(doc: &mut Document, view: &mut View, contents: &str, regex: &Regex, extend: bool) {
10391042 let text = doc.text();
10401043 let selection = doc.selection(view.id);
1041− let start = text.char_to_byte(selection.cursor());
1044+ let start = text.char_to_byte(selection.cursor(text.slice(..)));
10421045
10431046 // use find_at to find the next match after the cursor, loop around the end
10441047 // Careful, `Regex` uses `bytes` as offsets, not character indices!
@@ -2446,7 +2449,11 @@ fn goto_definition(cx: &mut Context) {
24462449
24472450 let offset_encoding = language_server.offset_encoding();
24482451
2449− let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
2452+ let pos = pos_to_lsp_pos(
2453+ doc.text(),
2454+ doc.selection(view.id).cursor(doc.text().slice(..)),
2455+ offset_encoding,
2456+ );
24502457
24512458 // TODO: handle fails
24522459 let future = language_server.goto_definition(doc.identifier(), pos, None);
@@ -2483,7 +2490,11 @@ fn goto_type_definition(cx: &mut Context) {
24832490
24842491 let offset_encoding = language_server.offset_encoding();
24852492
2486− let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
2493+ let pos = pos_to_lsp_pos(
2494+ doc.text(),
2495+ doc.selection(view.id).cursor(doc.text().slice(..)),
2496+ offset_encoding,
2497+ );
24872498
24882499 // TODO: handle fails
24892500 let future = language_server.goto_type_definition(doc.identifier(), pos, None);
@@ -2520,7 +2531,11 @@ fn goto_implementation(cx: &mut Context) {
25202531
25212532 let offset_encoding = language_server.offset_encoding();
25222533
2523− let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
2534+ let pos = pos_to_lsp_pos(
2535+ doc.text(),
2536+ doc.selection(view.id).cursor(doc.text().slice(..)),
2537+ offset_encoding,
2538+ );
25242539
25252540 // TODO: handle fails
25262541 let future = language_server.goto_implementation(doc.identifier(), pos, None);
@@ -2557,7 +2572,11 @@ fn goto_reference(cx: &mut Context) {
25572572
25582573 let offset_encoding = language_server.offset_encoding();
25592574
2560− let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
2575+ let pos = pos_to_lsp_pos(
2576+ doc.text(),
2577+ doc.selection(view.id).cursor(doc.text().slice(..)),
2578+ offset_encoding,
2579+ );
25612580
25622581 // TODO: handle fails
25632582 let future = language_server.goto_reference(doc.identifier(), pos, None);
@@ -2616,7 +2635,7 @@ fn goto_next_diag(cx: &mut Context) {
26162635 let editor = &mut cx.editor;
26172636 let (view, doc) = current!(editor);
26182637
2619− let cursor_pos = doc.selection(view.id).cursor();
2638+ let cursor_pos = doc.selection(view.id).cursor(doc.text().slice(..));
26202639 let diag = if let Some(diag) = doc
26212640 .diagnostics()
26222641 .iter()
@@ -2637,7 +2656,7 @@ fn goto_prev_diag(cx: &mut Context) {
26372656 let editor = &mut cx.editor;
26382657 let (view, doc) = current!(editor);
26392658
2640− let cursor_pos = doc.selection(view.id).cursor();
2659+ let cursor_pos = doc.selection(view.id).cursor(doc.text().slice(..));
26412660 let diag = if let Some(diag) = doc
26422661 .diagnostics()
26432662 .iter()
@@ -2665,7 +2684,7 @@ fn signature_help(cx: &mut Context) {
26652684
26662685 let pos = pos_to_lsp_pos(
26672686 doc.text(),
2668− doc.selection(view.id).cursor(),
2687+ doc.selection(view.id).cursor(doc.text().slice(..)),
26692688 language_server.offset_encoding(),
26702689 );
26712690
@@ -3403,13 +3422,14 @@ fn completion(cx: &mut Context) {
34033422 };
34043423
34053424 let offset_encoding = language_server.offset_encoding();
3425+ let cursor = doc.selection(view.id).cursor(doc.text().slice(..));
34063426
3407− let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
3427+ let pos = pos_to_lsp_pos(doc.text(), cursor, offset_encoding);
34083428
34093429 // TODO: handle fails
34103430 let future = language_server.completion(doc.identifier(), pos, None);
34113431
3412− let trigger_offset = doc.selection(view.id).cursor();
3432+ let trigger_offset = cursor;
34133433
34143434 cx.callback(
34153435 future,
@@ -3459,7 +3479,7 @@ fn hover(cx: &mut Context) {
34593479
34603480 let pos = pos_to_lsp_pos(
34613481 doc.text(),
3462− doc.selection(view.id).cursor(),
3482+ doc.selection(view.id).cursor(doc.text().slice(..)),
34633483 language_server.offset_encoding(),
34643484 );
34653485
@@ -3525,7 +3545,7 @@ fn match_brackets(cx: &mut Context) {
35253545 let (view, doc) = current!(cx.editor);
35263546
35273547 if let Some(syntax) = doc.syntax() {
3528− let pos = doc.selection(view.id).cursor();
3548+ let pos = doc.selection(view.id).cursor(doc.text().slice(..));
35293549 if let Some(pos) = match_brackets::find(syntax, doc.text(), pos) {
35303550 let selection = Selection::point(pos);
35313551 doc.set_selection(view.id, selection);
@@ -3629,7 +3649,7 @@ fn align_view_bottom(cx: &mut Context) {
36293649
36303650fn align_view_middle(cx: &mut Context) {
36313651 let (view, doc) = current!(cx.editor);
3632− let pos = doc.selection(view.id).cursor();
3652+ let pos = doc.selection(view.id).cursor(doc.text().slice(..));
36333653 let pos = coords_at_pos(doc.text().slice(..), pos);
36343654
36353655 const OFFSET: usize = 7; // gutters