-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
added tab to insert mode #2
Conversation
helix-core/src/state.rs
Outdated
let line_start = text.line_to_char(line); | ||
let col = text.slice(line_start..pos).len_chars(); | ||
let mut x: usize = 0; | ||
let line_slice = text.line(line).slice(..col); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simplify this:
pub fn screen_coords_at_pos(text: &RopeSlice, pos: usize) -> Coords {
let line = text.char_to_line(pos);
let line_start = text.line_to_char(line);
let line_slice = text.slice(line_start..pos);
let mut x = 0;
...
`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said, this returns (screen_x, line_number)
. What we want is (screen_y, screen_x)
so representing (row, col)
. You should move this to editor.rs
screen_coords_at_pos(view: &View, text: &RopeSlice, pos: usize) -> Coords
and use view.first_line
& last_line on screen to calculate the row.
Add a function called last_line to View
/// Calculates the last visible line on screen
pub fn last_line(&self, viewport: Rect) -> usize {
std::cmp::min(
(self.first_line + viewport.height - 1) as usize,
self.state.doc().len_lines() - 1,
);
}
Put this in the editor.rs file
/// Translates a document position to an absolute position in the terminal.
pub fn screen_coords_at_pos(view: &View, text: &RopeSlice, pos: usize) -> Option<Position> {
let line = text.char_to_line(pos);
if line < self.first_line || line > self.last_line() {
// Line is not visible on screen
return None;
}
let line_start = text.line_to_char(line);
let line_slice = text.slice(line_start..pos);
let mut col = 0;
... for loop etc
let row = line - view.first_line;
Some(Position::new(row, col))
}
Then you can also replace
helix/helix-term/src/editor.rs
Lines 88 to 91 in 7b4a4f6
let last_line = std::cmp::min( | |
(view.first_line + viewport.height - 1) as usize, | |
view.state.doc().len_lines() - 1, | |
); |
last_line()
54f618a
to
4393e1c
Compare
4393e1c
to
dc11124
Compare
Sticky context shows line number
Sticky context shows line number
add generators, switch statements and cases to ecma queries
Add editor-switch-action! command to be able to switch to an existing buffer
Cursor isn't rendering properly when using tabs and I'm not sure why. Should move for 4 characters to the right but only moves for 1.