vtHelp = ViewType{1, true, true}
vtLog = ViewType{2, true, true}
vtScratch = ViewType{3, false, true}
vtHelp = ViewType{1, true, true}
vtLog = ViewType{2, true, true}
vtScratch = ViewType{3, false, true}
// Since tcell doesn't differentiate between a mouse release event
// and a mouse move event with no keys pressed, we need to keep
// Since tcell doesn't differentiate between a mouse release event
// and a mouse move event with no keys pressed, we need to keep
// lastCutTime stores when the last ctrl+k was issued.
// It is used for clearing the clipboard to replace it with fresh cut lines.
// lastCutTime stores when the last ctrl+k was issued.
// It is used for clearing the clipboard to replace it with fresh cut lines.
// If there are unsaved changes, the user will be asked if the view can be closed
// causing them to lose the unsaved changes
func (v *View) CanClose() bool {
// If there are unsaved changes, the user will be asked if the view can be closed
// causing them to lose the unsaved changes
func (v *View) CanClose() bool {
v.lastClickTime = time.Time{}
}
// Open opens the given file in the view
func (v *View) Open(filename string) {
v.lastClickTime = time.Time{}
}
// Open opens the given file in the view
func (v *View) Open(filename string) {
- home, _ := homedir.Dir()
- filename = strings.Replace(filename, "~", home, 1)
+ filename = ReplaceHome(filename)
file, err := os.Open(filename)
fileInfo, _ := os.Stat(filename)
file, err := os.Open(filename)
fileInfo, _ := os.Stat(filename)
func (v *View) ExecuteActions(actions []func(*View, bool) bool) bool {
relocate := false
readonlyBindingsList := []string{"Delete", "Insert", "Backspace", "Cut", "Play", "Paste", "Move", "Add", "DuplicateLine", "Macro"}
for _, action := range actions {
readonlyBindingsResult := false
funcName := ShortFuncName(action)
func (v *View) ExecuteActions(actions []func(*View, bool) bool) bool {
relocate := false
readonlyBindingsList := []string{"Delete", "Insert", "Backspace", "Cut", "Play", "Paste", "Move", "Add", "DuplicateLine", "Macro"}
for _, action := range actions {
readonlyBindingsResult := false
funcName := ShortFuncName(action)
// check for readonly and if true only let key bindings get called if they do not change the contents.
for _, readonlyBindings := range readonlyBindingsList {
if strings.Contains(funcName, readonlyBindings) {
// check for readonly and if true only let key bindings get called if they do not change the contents.
for _, readonlyBindings := range readonlyBindingsList {
if strings.Contains(funcName, readonlyBindings) {
}
// HandleEvent handles an event passed by the main loop
func (v *View) HandleEvent(event tcell.Event) {
}
// HandleEvent handles an event passed by the main loop
func (v *View) HandleEvent(event tcell.Event) {
+ if v.Type == vtRaw {
+ v.Buf.Insert(v.Cursor.Loc, reflect.TypeOf(event).String()[7:])
+ v.Buf.Insert(v.Cursor.Loc, fmt.Sprintf(": %q\n", event.EscSeq()))
+
+ switch e := event.(type) {
+ case *tcell.EventKey:
+ if e.Key() == tcell.KeyCtrlQ {
+ v.Quit(true)
+ }
+ }
+
+ return
+ }
+
// This bool determines whether the view is relocated at the end of the function
// By default it's true because most events should cause a relocate
relocate := true
// This bool determines whether the view is relocated at the end of the function
// By default it's true because most events should cause a relocate
relocate := true
+ case *tcell.EventRaw:
+ for key, actions := range bindings {
+ if key.keyCode == -1 {
+ if e.EscSeq() == key.escape {
+ for _, c := range v.Buf.cursors {
+ ok := v.SetCursor(c)
+ if !ok {
+ break
+ }
+ relocate = false
+ relocate = v.ExecuteActions(actions) || relocate
+ }
+ v.SetCursor(&v.Buf.Cursor)
+ v.Buf.MergeCursors()
+ break
+ }
+ }
+ }
}
if e.Modifiers() == key.modifiers {
for _, c := range v.Buf.cursors {
}
if e.Modifiers() == key.modifiers {
for _, c := range v.Buf.cursors {
if !isBinding && e.Key() == tcell.KeyRune {
// Check viewtype if readonly don't insert a rune (readonly help and log view etc.)
if !isBinding && e.Key() == tcell.KeyRune {
// Check viewtype if readonly don't insert a rune (readonly help and log view etc.)
- v.Buf.Insert(v.Cursor.Loc, string(e.Rune()))
+
+ if v.isOverwriteMode {
+ next := v.Cursor.Loc
+ next.X++
+ v.Buf.Replace(v.Cursor.Loc, next, string(e.Rune()))
+ } else {
+ v.Buf.Insert(v.Cursor.Loc, string(e.Rune()))
+ }
for pl := range loadedPlugins {
_, err := Call(pl+".onRune", string(e.Rune()), v)
for pl := range loadedPlugins {
_, err := Call(pl+".onRune", string(e.Rune()), v)
for key, actions := range bindings {
if button == key.buttons && e.Modifiers() == key.modifiers {
for _, c := range v.Buf.cursors {
for key, actions := range bindings {
if button == key.buttons && e.Modifiers() == key.modifiers {
for _, c := range v.Buf.cursors {
if v.Buf.Settings["cursorline"].(bool) && tabs[curTab].CurView == v.Num &&
!v.Cursor.HasSelection() && v.Cursor.Y == realLineN {
if v.Buf.Settings["cursorline"].(bool) && tabs[curTab].CurView == v.Num &&
!v.Cursor.HasSelection() && v.Cursor.Y == realLineN {
style := GetColor("cursor-line")
fg, _, _ := style.Decompose()
style = style.Background(fg)
style := GetColor("cursor-line")
fg, _, _ := style.Decompose()
style = style.Background(fg)