Skip to content

Commit

Permalink
fix mouse stuff in files
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Jul 12, 2024
1 parent c137db3 commit a2dc423
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions config/keymap.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ toggle_tree_sitter_debug = 'f2'
debug_tree_sitter_nodes = 'f3'
show_current_diagnostic = 'ctrl+j'
show_definitions = 'alt+.'
show_declaration = 'ctrl+.'
character_left = 'left'
character_right = 'right'
word_left = 'ctrl+left'
Expand Down
7 changes: 7 additions & 0 deletions gopad/config/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type EditorKeyMap struct {
DebugTreeSitterNodes key.Binding
ShowCurrentDiagnostic key.Binding
ShowDefinitions key.Binding
ShowDeclaration key.Binding

CharacterLeft key.Binding
CharacterRight key.Binding
Expand Down Expand Up @@ -283,6 +284,7 @@ func DefaultKeyMapConfig() KeyMapConfig {
DebugTreeSitterNodes: "f3",
ShowCurrentDiagnostic: "ctrl+j",
ShowDefinitions: "alt+.",
ShowDeclaration: "ctrl+.",

CharacterLeft: "left",
CharacterRight: "right",
Expand Down Expand Up @@ -470,6 +472,7 @@ type EditorKeyConfig struct {
DebugTreeSitterNodes string `toml:"debug_tree_sitter_nodes"`
ShowCurrentDiagnostic string `toml:"show_current_diagnostic"`
ShowDefinitions string `toml:"show_definitions"`
ShowDeclaration string `toml:"show_declaration"`

CharacterLeft string `toml:"character_left"`
CharacterRight string `toml:"character_right"`
Expand Down Expand Up @@ -611,6 +614,10 @@ func (k EditorKeyConfig) KeyMap() EditorKeyMap {
key.WithKeys(k.ShowDefinitions),
key.WithHelp(k.ShowDefinitions, "show definitions"),
),
ShowDeclaration: key.NewBinding(
key.WithKeys(k.ShowDeclaration),
key.WithHelp(k.ShowDeclaration, "show declaration"),
),

CharacterLeft: key.NewBinding(
key.WithKeys(k.CharacterLeft),
Expand Down
41 changes: 31 additions & 10 deletions gopad/editor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ func (e Editor) Update(ctx tea.Context, msg tea.Msg) (Editor, tea.Cmd) {
row, col := f.GetFileZoneCursorPos(tea.MouseEvent(msg), z)
f.SetMark(row, col)
f.SetCursor(row, col)
return e, tea.Batch(cmds...)
overwriteCursorBlink = true
}
}
case tea.MouseUpMsg:
Expand All @@ -623,18 +623,9 @@ func (e Editor) Update(ctx tea.Context, msg tea.Msg) (Editor, tea.Cmd) {
}
cmds = append(cmds, f.Autocomplete().Update())
return e, tea.Batch(cmds...)
case mouse.MatchesZone(tea.MouseEvent(msg), z, tea.MouseLeft):
i, _ := strconv.Atoi(strings.TrimPrefix(z.ID(), ZoneFilePrefix))
e.SetFile(i)
return e, tea.Batch(cmds...)
case mouse.MatchesZone(tea.MouseEvent(msg), z, tea.MouseRight):
// TODO: open context menu?
return e, tea.Batch(cmds...)
case mouse.MatchesZone(tea.MouseEvent(msg), z, tea.MouseMiddle):
i, _ := strconv.Atoi(strings.TrimPrefix(z.ID(), ZoneFilePrefix))
cmds = append(cmds, file.CloseFile(e.files[i].Name()))
return e, tea.Batch(cmds...)

case mouse.Matches(tea.MouseEvent(msg), ZoneFileLanguage, tea.MouseLeft):
cmds = append(cmds, overlay.Open(NewSetLanguageOverlay()))
return e, tea.Batch(cmds...)
Expand All @@ -648,6 +639,36 @@ func (e Editor) Update(ctx tea.Context, msg tea.Msg) (Editor, tea.Cmd) {
return e, tea.Batch(cmds...)
}
}

for _, z := range zone.GetPrefix(ZoneFilePrefix) {
switch {
case mouse.MatchesZone(tea.MouseEvent(msg), z, tea.MouseLeft):
i, _ := strconv.Atoi(strings.TrimPrefix(z.ID(), ZoneFilePrefix))
e.SetFile(i)
return e, tea.Batch(cmds...)
case mouse.MatchesZone(tea.MouseEvent(msg), z, tea.MouseRight):
// TODO: open context menu?
return e, tea.Batch(cmds...)
case mouse.MatchesZone(tea.MouseEvent(msg), z, tea.MouseMiddle):
i, _ := strconv.Atoi(strings.TrimPrefix(z.ID(), ZoneFilePrefix))
cmds = append(cmds, file.CloseFile(e.files[i].Name()))
return e, tea.Batch(cmds...)
}
}

switch {
case mouse.Matches(tea.MouseEvent(msg), ZoneFileLanguage, tea.MouseLeft):
cmds = append(cmds, overlay.Open(NewSetLanguageOverlay()))
return e, tea.Batch(cmds...)
case mouse.Matches(tea.MouseEvent(msg), ZoneFileLineEnding, tea.MouseLeft):
log.Println("file line ending zone")
// cmds = append(cmds, overlay.Open(NewSetLineEndingOverlay()))
return e, tea.Batch(cmds...)
case mouse.Matches(tea.MouseEvent(msg), ZoneFileEncoding, tea.MouseLeft):
log.Println("file encoding zone")
// cmds = append(cmds, overlay.Open(NewSetEncodingOverlay()))
return e, tea.Batch(cmds...)
}
case tea.MouseMotionMsg:
for _, z := range zone.GetPrefix(file.ZoneFileLinePrefix) {
switch {
Expand Down

0 comments on commit a2dc423

Please sign in to comment.