Compare commits
No commits in common. "52b07bfc0b6781060478798b30e67b09123356fc" and "03370069863db506bc74114b75f3d07533780811" have entirely different histories.
52b07bfc0b
...
0337006986
3 changed files with 30 additions and 9 deletions
|
|
@ -20,6 +20,7 @@ pub enum Action {
|
|||
Char(char), // Insert a character
|
||||
Indent(bool), // Indent (indent vs deindent)
|
||||
Move(Dir, Dist, bool, bool), // Move the cursor (dir, dist, retain_base, word)
|
||||
Pan(Dir, Dist), // Pan the view window
|
||||
PaneMove(Dir), // Move panes
|
||||
PaneOpen(Dir), // Create a new pane
|
||||
PaneClose, // Close the current pane
|
||||
|
|
@ -66,7 +67,8 @@ pub enum Dist {
|
|||
pub enum MouseAction {
|
||||
Click,
|
||||
Drag,
|
||||
Scroll(Dir),
|
||||
ScrollDown,
|
||||
ScrollUp,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -216,6 +218,19 @@ impl RawEvent {
|
|||
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> {
|
||||
if matches!(
|
||||
&self.0,
|
||||
|
|
@ -487,8 +502,8 @@ impl RawEvent {
|
|||
|
||||
if let Some(pos) = area.contains([ev.column as isize, ev.row as isize]) {
|
||||
let action = match ev.kind {
|
||||
MouseEventKind::ScrollUp => MouseAction::Scroll(Dir::Up),
|
||||
MouseEventKind::ScrollDown => MouseAction::Scroll(Dir::Down),
|
||||
MouseEventKind::ScrollUp => MouseAction::ScrollUp,
|
||||
MouseEventKind::ScrollDown => MouseAction::ScrollDown,
|
||||
MouseEventKind::Down(MouseButton::Left) => {
|
||||
*drag_id_counter += 1;
|
||||
MouseAction::Click
|
||||
|
|
|
|||
|
|
@ -212,9 +212,9 @@ impl Highlighter {
|
|||
// Builtins
|
||||
.with(TokenKind::Macro, r"\b[(True)(False)(None)]\b")
|
||||
// Doc comments
|
||||
.with(TokenKind::Doc, r"^[[:space:]]##[^$]*$")
|
||||
.with(TokenKind::Doc, r"^##[^$]*$")
|
||||
// Comments
|
||||
.with(TokenKind::Comment, r"#[^$]*$")
|
||||
.with(TokenKind::Comment, r"^#[^$]*$")
|
||||
.clike()
|
||||
}
|
||||
|
||||
|
|
@ -227,9 +227,9 @@ impl Highlighter {
|
|||
// Builtins
|
||||
.with(TokenKind::Macro, r"\b[(True)(False)]\b")
|
||||
// Doc comments
|
||||
.with(TokenKind::Doc, r"^[[:space:]]##[^$]*$")
|
||||
.with(TokenKind::Doc, r"^##[^$]*$")
|
||||
// Comments
|
||||
.with(TokenKind::Comment, r"#[^$]*$")
|
||||
.with(TokenKind::Comment, r"^#[^$]*$")
|
||||
// Attributes
|
||||
.with(TokenKind::Attribute, r"\$!?\[[^\]]*\]")
|
||||
.clike()
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ impl Input {
|
|||
e.to_char()
|
||||
.map(Action::Char)
|
||||
.or_else(|| e.to_move())
|
||||
.or_else(|| e.to_pan())
|
||||
.or_else(|| e.to_select_token())
|
||||
.or_else(|| e.to_select_all())
|
||||
.or_else(|| e.to_indent())
|
||||
|
|
@ -97,8 +98,13 @@ impl Input {
|
|||
self.refocus(buffer, cursor_id);
|
||||
Ok(Resp::handled(None))
|
||||
}
|
||||
Some(Action::Mouse(MouseAction::Scroll(dir), pos, _, _)) if is_doc => {
|
||||
let dist = [1, 1];
|
||||
Some(Action::Pan(dir, dist)) if is_doc => {
|
||||
let dist = match dist {
|
||||
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 {
|
||||
Dir::Up => [0, -1],
|
||||
Dir::Down => [0, 1],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue