Skip to content

Commit

Permalink
feat(ui): add cut functionality to code editor
Browse files Browse the repository at this point in the history
- Implement Cut method in CodeView struct
- Add cut option to code context menu
- Integrate cut command with keyboard shortcuts
- Update keymap to include new vi_cut_text command
  • Loading branch information
wellcomez committed Nov 11, 2024
1 parent 0d8ddb1 commit a9d2ec0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/ui/CodeContextMenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ func update_selection_menu(code *CodeView) {
code.main.CopyToClipboard(data)

}, hide: menudata.previous_selection.emtry()},
{item: create_menu_item("Cut"), handle: func() {
code.Cut()
}, hide: menudata.previous_selection.emtry()},
{item: create_menu_item("Paste"), handle: func() {
code.Paste()
}, hide: !has_clip},
Expand Down
2 changes: 2 additions & 0 deletions pkg/ui/codeeditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ type IEditorContent interface {
deleteword()
deltext()

Cut()

//code content
GetLines(begin, end int) []string
copyline(bool)
Expand Down
5 changes: 5 additions & 0 deletions pkg/ui/codeview.go
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,11 @@ func (v *codetextview) DeleteWordRight() bool {
}
return true
}
func (code *CodeView) Cut() {
checker := code.NewChangeChecker()
defer checker.End()
code.view.Cut()
}
func (code *CodeView) deleteword() {
checker := code.NewChangeChecker()
defer checker.End()
Expand Down
10 changes: 8 additions & 2 deletions pkg/ui/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
zoomout
copy_data
vi_copy_text
vi_cut_text
vi_del_text
vi_undo
vi_save
Expand Down Expand Up @@ -415,18 +416,23 @@ func get_cmd_actor(m MainService, id command_id) cmdactor {
m.current_editor().action_page_down(false)
return true
}}
case vi_cut_text:
return cmdactor{id, "Cut", func() bool {
m.current_editor().Cut()
return true
}}
case vi_copy_text:
return cmdactor{id, "Copy", func() bool {
m.current_editor().copyline(false)
return true
}}
case vi_del_text:
return cmdactor{id, "Del", func() bool {
return cmdactor{id, "Delete", func() bool {
m.current_editor().deltext()
return true
}}
case vi_del_line:
return cmdactor{id, "Delete", func() bool {
return cmdactor{id, "Delete Line", func() bool {
m.current_editor().deleteline()
return true
}}
Expand Down

0 comments on commit a9d2ec0

Please sign in to comment.