Compare commits

...

2 commits

Author SHA1 Message Date
52b07bfc0b Fixed scroll panning 2025-09-30 21:12:34 +01:00
cde5905ae0 Better python/tao comment highlighting 2025-09-30 20:58:37 +01:00
3 changed files with 9 additions and 30 deletions

View file

@ -20,7 +20,6 @@ pub enum Action {
Char(char), // Insert a character Char(char), // Insert a character
Indent(bool), // Indent (indent vs deindent) Indent(bool), // Indent (indent vs deindent)
Move(Dir, Dist, bool, bool), // Move the cursor (dir, dist, retain_base, word) Move(Dir, Dist, bool, bool), // Move the cursor (dir, dist, retain_base, word)
Pan(Dir, Dist), // Pan the view window
PaneMove(Dir), // Move panes PaneMove(Dir), // Move panes
PaneOpen(Dir), // Create a new pane PaneOpen(Dir), // Create a new pane
PaneClose, // Close the current pane PaneClose, // Close the current pane
@ -67,8 +66,7 @@ pub enum Dist {
pub enum MouseAction { pub enum MouseAction {
Click, Click,
Drag, Drag,
ScrollDown, Scroll(Dir),
ScrollUp,
} }
#[derive(Debug)] #[derive(Debug)]
@ -218,19 +216,6 @@ impl RawEvent {
Some(Action::Move(dir, dist, retain_base, word)) Some(Action::Move(dir, dist, retain_base, word))
} }
pub fn to_pan(&self) -> Option<Action> {
let (dir, dist) = match &self.0 {
TerminalEvent::Mouse(ev) => match ev.kind {
MouseEventKind::ScrollUp => (Dir::Up, Dist::Char),
MouseEventKind::ScrollDown => (Dir::Down, Dist::Char),
_ => return None,
},
_ => return None,
};
Some(Action::Pan(dir, dist))
}
pub fn to_select_token(&self) -> Option<Action> { pub fn to_select_token(&self) -> Option<Action> {
if matches!( if matches!(
&self.0, &self.0,
@ -502,8 +487,8 @@ impl RawEvent {
if let Some(pos) = area.contains([ev.column as isize, ev.row as isize]) { if let Some(pos) = area.contains([ev.column as isize, ev.row as isize]) {
let action = match ev.kind { let action = match ev.kind {
MouseEventKind::ScrollUp => MouseAction::ScrollUp, MouseEventKind::ScrollUp => MouseAction::Scroll(Dir::Up),
MouseEventKind::ScrollDown => MouseAction::ScrollDown, MouseEventKind::ScrollDown => MouseAction::Scroll(Dir::Down),
MouseEventKind::Down(MouseButton::Left) => { MouseEventKind::Down(MouseButton::Left) => {
*drag_id_counter += 1; *drag_id_counter += 1;
MouseAction::Click MouseAction::Click

View file

@ -212,9 +212,9 @@ impl Highlighter {
// Builtins // Builtins
.with(TokenKind::Macro, r"\b[(True)(False)(None)]\b") .with(TokenKind::Macro, r"\b[(True)(False)(None)]\b")
// Doc comments // Doc comments
.with(TokenKind::Doc, r"^##[^$]*$") .with(TokenKind::Doc, r"^[[:space:]]##[^$]*$")
// Comments // Comments
.with(TokenKind::Comment, r"^#[^$]*$") .with(TokenKind::Comment, r"#[^$]*$")
.clike() .clike()
} }
@ -227,9 +227,9 @@ impl Highlighter {
// Builtins // Builtins
.with(TokenKind::Macro, r"\b[(True)(False)]\b") .with(TokenKind::Macro, r"\b[(True)(False)]\b")
// Doc comments // Doc comments
.with(TokenKind::Doc, r"^##[^$]*$") .with(TokenKind::Doc, r"^[[:space:]]##[^$]*$")
// Comments // Comments
.with(TokenKind::Comment, r"^#[^$]*$") .with(TokenKind::Comment, r"#[^$]*$")
// Attributes // Attributes
.with(TokenKind::Attribute, r"\$!?\[[^\]]*\]") .with(TokenKind::Attribute, r"\$!?\[[^\]]*\]")
.clike() .clike()

View file

@ -66,7 +66,6 @@ impl Input {
e.to_char() e.to_char()
.map(Action::Char) .map(Action::Char)
.or_else(|| e.to_move()) .or_else(|| e.to_move())
.or_else(|| e.to_pan())
.or_else(|| e.to_select_token()) .or_else(|| e.to_select_token())
.or_else(|| e.to_select_all()) .or_else(|| e.to_select_all())
.or_else(|| e.to_indent()) .or_else(|| e.to_indent())
@ -98,13 +97,8 @@ impl Input {
self.refocus(buffer, cursor_id); self.refocus(buffer, cursor_id);
Ok(Resp::handled(None)) Ok(Resp::handled(None))
} }
Some(Action::Pan(dir, dist)) if is_doc => { Some(Action::Mouse(MouseAction::Scroll(dir), pos, _, _)) if is_doc => {
let dist = match dist { let dist = [1, 1];
Dist::Char => [1, 1],
Dist::Page => self.last_area.size().map(|s| s.saturating_sub(3).max(1)),
// TODO: Don't just use an arbitrary very large number
Dist::Doc => [1_000_000_000; 2],
};
let dfocus = match dir { let dfocus = match dir {
Dir::Up => [0, -1], Dir::Up => [0, -1],
Dir::Down => [0, 1], Dir::Down => [0, 1],