diff options
author | Blaž Hrastnik | 2022-06-21 16:38:21 +0000 |
---|---|---|
committer | GitHub | 2022-06-21 16:38:21 +0000 |
commit | 458b89e21dcf76bbf9ca6ba237bd334f4922722d (patch) | |
tree | f859642d007db7274d3cd657ecaa59b1ec014cd8 /helix-term | |
parent | 5f7c247430998fabceb55d4689118dd75e2bdfb1 (diff) | |
parent | 6a3f7f2c399f0b92cef97b0c85ebe976fd7cfcac (diff) |
Merge branch 'master' into test-harness
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 38 | ||||
-rw-r--r-- | helix-term/src/health.rs | 15 | ||||
-rw-r--r-- | helix-term/src/keymap/default.rs | 2 | ||||
-rw-r--r-- | helix-term/src/ui/editor.rs | 8 |
4 files changed, 43 insertions, 20 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 4dfa6ec8..897712f0 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -16,14 +16,14 @@ use helix_core::{ line_ending::{get_line_ending_of_str, line_end_char_index, str_is_line_ending}, match_brackets, movement::{self, Direction}, - object, pos_at_coords, + object, pos_at_coords, pos_at_visual_coords, regex::{self, Regex, RegexBuilder}, search::{self, CharMatcher}, selection, shellwords, surround, textobject, tree_sitter::Node, unicode::width::UnicodeWidthChar, - LineEnding, Position, Range, Rope, RopeGraphemes, RopeSlice, Selection, SmallVec, Tendril, - Transaction, + visual_coords_at_pos, LineEnding, Position, Range, Rope, RopeGraphemes, RopeSlice, Selection, + SmallVec, Tendril, Transaction, }; use helix_view::{ clipboard::ClipboardType, @@ -395,6 +395,8 @@ impl MappableCommand { goto_prev_parameter, "Goto previous parameter", goto_next_comment, "Goto next comment", goto_prev_comment, "Goto previous comment", + goto_next_test, "Goto next test", + goto_prev_test, "Goto previous test", goto_next_paragraph, "Goto next paragraph", goto_prev_paragraph, "Goto previous paragraph", dap_launch, "Launch debug target", @@ -509,7 +511,7 @@ fn no_op(_cx: &mut Context) {} fn move_impl<F>(cx: &mut Context, move_fn: F, dir: Direction, behaviour: Movement) where - F: Fn(RopeSlice, Range, Direction, usize, Movement) -> Range, + F: Fn(RopeSlice, Range, Direction, usize, Movement, usize) -> Range, { let count = cx.count(); let (view, doc) = current!(cx.editor); @@ -518,7 +520,7 @@ where let selection = doc .selection(view.id) .clone() - .transform(|range| move_fn(text, range, dir, count, behaviour)); + .transform(|range| move_fn(text, range, dir, count, behaviour, doc.tab_width())); doc.set_selection(view.id, selection); } @@ -1410,9 +1412,10 @@ fn copy_selection_on_line(cx: &mut Context, direction: Direction) { range.head }; - // TODO: this should use visual offsets / pos_at_screen_coords - let head_pos = coords_at_pos(text, head); - let anchor_pos = coords_at_pos(text, range.anchor); + let tab_width = doc.tab_width(); + + let head_pos = visual_coords_at_pos(text, head, tab_width); + let anchor_pos = visual_coords_at_pos(text, range.anchor, tab_width); let height = std::cmp::max(head_pos.row, anchor_pos.row) - std::cmp::min(head_pos.row, anchor_pos.row) @@ -1442,12 +1445,13 @@ fn copy_selection_on_line(cx: &mut Context, direction: Direction) { break; } - let anchor = pos_at_coords(text, Position::new(anchor_row, anchor_pos.col), true); - let head = pos_at_coords(text, Position::new(head_row, head_pos.col), true); + let anchor = + pos_at_visual_coords(text, Position::new(anchor_row, anchor_pos.col), tab_width); + let head = pos_at_visual_coords(text, Position::new(head_row, head_pos.col), tab_width); // skip lines that are too short - if coords_at_pos(text, anchor).col == anchor_pos.col - && coords_at_pos(text, head).col == head_pos.col + if visual_coords_at_pos(text, anchor, tab_width).col == anchor_pos.col + && visual_coords_at_pos(text, head, tab_width).col == head_pos.col { if is_primary { primary_index = ranges.len(); @@ -4105,6 +4109,14 @@ fn goto_prev_comment(cx: &mut Context) { goto_ts_object_impl(cx, "comment", Direction::Backward) } +fn goto_next_test(cx: &mut Context) { + goto_ts_object_impl(cx, "test", Direction::Forward) +} + +fn goto_prev_test(cx: &mut Context) { + goto_ts_object_impl(cx, "test", Direction::Backward) +} + fn select_textobject_around(cx: &mut Context) { select_textobject(cx, textobject::TextObject::Around); } @@ -4148,6 +4160,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) { 'f' => textobject_treesitter("function", range), 'a' => textobject_treesitter("parameter", range), 'o' => textobject_treesitter("comment", range), + 't' => textobject_treesitter("test", range), 'p' => textobject::textobject_paragraph(text, range, objtype, count), 'm' => textobject::textobject_surround_closest(text, range, objtype, count), // TODO: cancel new ranges if inconsistent surround matches across lines @@ -4177,6 +4190,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) { ("f", "Function (tree-sitter)"), ("a", "Argument/parameter (tree-sitter)"), ("o", "Comment (tree-sitter)"), + ("t", "Test (tree-sitter)"), ("m", "Matching delimiter under cursor"), (" ", "... or any character acting as a pair"), ]; diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index bd74f478..f64e121d 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -1,4 +1,7 @@ -use crossterm::style::{Color, Print, Stylize}; +use crossterm::{ + style::{Color, Print, Stylize}, + tty::IsTty, +}; use helix_core::config::{default_syntax_loader, user_syntax_loader}; use helix_loader::grammar::load_runtime_file; use std::io::Write; @@ -106,17 +109,19 @@ pub fn languages_all() -> std::io::Result<()> { let terminal_cols = crossterm::terminal::size().map(|(c, _)| c).unwrap_or(80); let column_width = terminal_cols as usize / headings.len(); + let is_terminal = std::io::stdout().is_tty(); let column = |item: &str, color: Color| { - let data = format!( + let mut data = format!( "{:width$}", item.get(..column_width - 2) .map(|s| format!("{}…", s)) .unwrap_or_else(|| item.to_string()), width = column_width, - ) - .stylize() - .with(color); + ); + if is_terminal { + data = data.stylize().with(color).to_string(); + } // We can't directly use println!() because of // https://github.com/crossterm-rs/crossterm/issues/589 diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 0f0b09dd..c3695117 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -104,6 +104,7 @@ pub fn default() -> HashMap<Mode, Keymap> { "c" => goto_prev_class, "a" => goto_prev_parameter, "o" => goto_prev_comment, + "t" => goto_prev_test, "p" => goto_prev_paragraph, "space" => add_newline_above, }, @@ -114,6 +115,7 @@ pub fn default() -> HashMap<Mode, Keymap> { "c" => goto_next_class, "a" => goto_next_parameter, "o" => goto_next_comment, + "t" => goto_next_test, "p" => goto_next_paragraph, "space" => add_newline_below, }, diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index f074d9f1..a8027d1b 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -20,7 +20,7 @@ use helix_core::{ use helix_view::{ document::{Mode, SCRATCH_BUFFER_NAME}, editor::{CompleteAction, CursorShapeConfig}, - graphics::{CursorKind, Modifier, Rect, Style}, + graphics::{Color, CursorKind, Modifier, Rect, Style}, input::KeyEvent, keyboard::{KeyCode, KeyModifiers}, Document, Editor, Theme, View, @@ -170,7 +170,9 @@ impl EditorView { theme: &Theme, ) { let editor_rulers = &editor.config().rulers; - let ruler_theme = theme.get("ui.virtual.ruler"); + let ruler_theme = theme + .try_get("ui.virtual.ruler") + .unwrap_or_else(|| Style::default().bg(Color::Red)); let rulers = doc .language_config() @@ -1046,7 +1048,7 @@ impl EditorView { let mut selection = doc.selection(view.id).clone(); let primary = selection.primary_mut(); - *primary = Range::new(primary.anchor, pos); + *primary = primary.put_cursor(doc.text().slice(..), pos, true); doc.set_selection(view.id, selection); EventResult::Consumed(None) } |