Skip to content

Commit

Permalink
refactor(ui): add external open functionality and improve command han…
Browse files Browse the repository at this point in the history
…dling

- Add external open command and bind to 'external' keyword
- Refactor CodeContextMenu to use the new command
- Implement open_extenal function for opening files externally
- Update MainService interface and add open_externl command ID
- Modify create_main_layout to conditionally add cmdline input based on Vim enable status
  • Loading branch information
wellcomez committed Nov 11, 2024
1 parent d9d1331 commit 82f0bee
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
16 changes: 2 additions & 14 deletions pkg/ui/CodeContextMenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
"github.com/tectiv3/go-lsp"
"zen108.com/lspvi/pkg/debug"
// "zen108.com/lspvi/pkg/debug"
lspcore "zen108.com/lspvi/pkg/lsp"
)

Expand Down Expand Up @@ -211,19 +211,7 @@ func update_selection_menu(code *CodeView) {
{
item: create_menu_item("External open "),
handle: func() {
filename := code.Path()
yes, err := isDirectory(filename)
if err != nil {
return
}
debug.InfoLog("external open tty=", tty)
if proxy != nil {
proxy.open_in_web(filename)
} else {
if !yes {
openfile(filename)
}
}
get_cmd_actor(main, open_externl).handle()
},
},
{item: create_menu_item(menu_break_line), handle: func() {
Expand Down
1 change: 1 addition & 0 deletions pkg/ui/cmdline.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func new_cmdline(main *mainui) *cmdline {
return
}
code.cmds = []cmd_processor{
create_cmd_item(open_externl, []string{"external"}),
create_cmd_item(next_error, []string{"en"}),
create_cmd_item(prev_error, []string{"ep"}),
create_cmd_item(vi_quick_prev, []string{"cp"}),
Expand Down
15 changes: 15 additions & 0 deletions pkg/ui/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const (
cmd_reload
split_right
close_tab
open_externl
)

func (m *mainui) create_menu_item(id command_id, handle func()) context_menu_item {
Expand Down Expand Up @@ -144,6 +145,12 @@ func get_cmd_actor(m MainService, id command_id) cmdactor {
SplitClose(m.current_editor()).handle()
return true
}}
case open_externl:
return cmdactor{id, "Open external", func() bool {
filename := m.current_editor().Path()
open_extenal(filename)
return true
}}
case split_right:
return cmdactor{id, "Split right", func() bool {
editor := m.current_editor()
Expand Down Expand Up @@ -544,6 +551,14 @@ func get_cmd_actor(m MainService, id command_id) cmdactor {
}
}

func open_extenal(filename string) {
if proxy != nil {
proxy.open_in_web(filename)
} else {
openfile(filename)
}
}

func (cmdline *cmdline) set_escape_search_mode(word string) {
cmdline.find_history.add_if_need(command_history_record{word, true})
cmdline.Vim.EnterEscape()
Expand Down
9 changes: 5 additions & 4 deletions pkg/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ type MainService interface {

//screen


//view manager
IViewManager

Expand Down Expand Up @@ -1068,11 +1067,13 @@ func (main *mainui) create_main_layout(editor_area *flex_area, console_layout *f
main_layout.set_dir(tview.FlexRow)
editor_area.Height = 100
console_layout.Height = 80
main_layout.
var layout = main_layout.
AddItem(editor_area, 0, editor_area.Height, true).
AddItem(console_layout, 0, console_layout.Height, false).
AddItem(tab_area, 1, 0, false).
AddItem(main.cmdline.input, 3, 1, false)
AddItem(tab_area, 1, 0, false)
if main.CmdLine().Vim.Enable() {
layout.AddItem(main.cmdline.input, 3, 1, false)
}
// main_layout.SetBorder(true)
main.layout = &rootlayout{
editor_area: editor_area,
Expand Down

0 comments on commit 82f0bee

Please sign in to comment.