Compare commits
3 Commits
5fd2620121
...
075b74afca
Author | SHA1 | Date |
---|---|---|
mars | 075b74afca | |
mars | 74e1bd88c6 | |
mars | 9558cdadb4 |
|
@ -33,6 +33,7 @@ pub fn load_actions() -> HashMap<String, Action> {
|
|||
("page_down", page_down),
|
||||
("goto_line_start", goto_line_start),
|
||||
("goto_line_end", goto_line_end),
|
||||
("goto_first_nonwhitespace", goto_first_nonwhitespace),
|
||||
("command_mode", command_mode),
|
||||
("normal_mode", normal_mode),
|
||||
("visual_mode", visual_mode),
|
||||
|
@ -88,6 +89,10 @@ pub fn goto_line_end(state: &mut State) {
|
|||
state.cursor = state.buffer.cursor_at_line_end(state.cursor.line);
|
||||
}
|
||||
|
||||
pub fn goto_first_nonwhitespace(state: &mut State) {
|
||||
state.cursor = state.buffer.cursor_at_first_nonwhitespace(state.cursor.line);
|
||||
}
|
||||
|
||||
pub fn command_mode(state: &mut State) {
|
||||
state.mode = Mode::Command(Default::default());
|
||||
}
|
||||
|
@ -117,11 +122,13 @@ pub fn append_mode(state: &mut State) {
|
|||
}
|
||||
|
||||
pub fn insert_at_line_start(state: &mut State) {
|
||||
state.set_error("insert_at_line_start is unimplemented");
|
||||
goto_first_nonwhitespace(state);
|
||||
insert_mode(state);
|
||||
}
|
||||
|
||||
pub fn insert_at_line_end(state: &mut State) {
|
||||
state.set_error("insert_at_line_end is unimplemented");
|
||||
goto_line_end(state);
|
||||
insert_mode(state);
|
||||
}
|
||||
|
||||
pub fn open_below(state: &mut State) {
|
||||
|
|
|
@ -21,11 +21,11 @@ use std::io::Write;
|
|||
use std::ops::Range;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crossterm::{cursor, ExecutableCommand, QueueableCommand};
|
||||
use crossterm::{cursor, QueueableCommand};
|
||||
use parking_lot::Mutex;
|
||||
use ropey::Rope;
|
||||
use syntect::easy::ScopeRangeIterator;
|
||||
use syntect::parsing::{BasicScopeStackOp, ParseState, Scope, ScopeStack, SyntaxSet};
|
||||
use syntect::parsing::{BasicScopeStackOp, ParseState, ScopeStack, SyntaxSet};
|
||||
|
||||
use crate::theme::{Style, StyleStore};
|
||||
use crate::{Cursor, Direction};
|
||||
|
@ -274,11 +274,12 @@ impl Buffer {
|
|||
pub fn cursor_at_first_nonwhitespace(&self, line: usize) -> Cursor {
|
||||
if let Some(line_slice) = self.text.get_line(line) {
|
||||
let mut column = 0;
|
||||
for c in line_slice.chars().reversed() {
|
||||
column += 1;
|
||||
for c in line_slice.chars() {
|
||||
if !c.is_whitespace() {
|
||||
break;
|
||||
}
|
||||
|
||||
column += 1;
|
||||
}
|
||||
|
||||
Cursor { line, column }
|
||||
|
|
|
@ -53,6 +53,7 @@ impl Default for Keybinds {
|
|||
let goto_keys = &[
|
||||
(Char('h'), goto_line_start as Action),
|
||||
(Char('l'), goto_line_end),
|
||||
(Char('s'), goto_first_nonwhitespace),
|
||||
];
|
||||
|
||||
let normalish_keys = [
|
||||
|
|
Loading…
Reference in New Issue