-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle line numbers in "copy" operations
Copy operations include an "ln" field that is used to update the line number of the lines being copied. If we ignore it, we end up with inconsistent line numbers in the cache. For instance, consider the following file (`|` indicates the cursor position): ``` a| b ``` On pressing "Enter" to insert a newline, the following update is being sent: {"update":{"annotations":[{"n":1,"payloads":null,"ranges":[[1,0,1,0]],"type":"selection"}],"ops":[{"lines":[{"ln":1,"styles":[0,2,8],"text":"a\n"},{"cursor":[0],"ln":2,"styles":[0,1,8],"text":"\n"}],"n":2,"op":"ins"},{"n":1,"op":"skip"},{"ln":3,"n":1,"op":"copy"}],"pristine":false},"view_id":"view-id-2"} The intersting operation is {"ln":3,"n":1,"op":"copy"}. Before the update we have the following line cache: LineCache { invalid_before: 0, lines: [Line { text: "a", cursor: [1], styles: [StyleDef { offset: 0, length: 2, style_id: 8 }], line_num: Some(1) }, Line { text: "b", cursor: [], styles: [StyleDef { offset: 0, length: 1, style_id: 8 }], line_num: Some(2) }], invalid_after: 0 } If we ignore the "ln" field, we end up with the following cache where we have to lines number "2" ("" and "b"): LineCache { invalid_before: 0, lines: [Line { text: "a", cursor: [], styles: [StyleDef { offset: 0, length: 2, style_id: 8 }], line_num: Some(1) }, Line { text: "", cursor: [0], styles: [StyleDef { offset: 0, length: 1, style_id: 8 }], line_num: Some(2) }, Line { text: "b", cursor: [], styles: [StyleDef { offset: 0, length: 1, style_id: 8 }], line_num: Some(2) }], invalid_after: 0 } because the "b" line is copied as is. With this commit, we end up with the following line cache: LineCache { invalid_before: 0, lines: [Line { text: "a", cursor: [], styles: [StyleDef { offset: 0, length: 2, style_id: 8 }], line_num: Some(1) }, Line { text: "", cursor: [0], styles: [StyleDef { offset: 0, length: 1, style_id: 8 }], line_num: Some(2) }, Line { text: "b", cursor: [], styles: [StyleDef { offset: 0, length: 1, style_id: 8 }], line_num: Some(3) }], invalid_after: 0 }
- Loading branch information
1 parent
0628c9c
commit cd57fec
Showing
3 changed files
with
101 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters