Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve text editing support in parameter inputs #249

Open
RamiAwar opened this issue Jan 30, 2024 · 0 comments
Open

Improve text editing support in parameter inputs #249

RamiAwar opened this issue Jan 30, 2024 · 0 comments

Comments

@RamiAwar
Copy link
Collaborator

RamiAwar commented Jan 30, 2024

Parameter inputs don't allow for natural text editing, ex.

I think this is what #162 was trying to achieve.

Ctrl+Left or Cmd+Left to jump to start of line
Ctrl+Backspace or Cmd+Backspace to clear all (useful when we have a default value we want to clear)
...

gocui seems to support defining a custom editor, we should add support for that. Some boilerplate code from komanda:

ui.Editor = gocui.EditorFunc(simpleEditor)
g.SetManagerFunc(ui.Layout)
func simpleEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
	var tab = false
	var inHistroy = false

	switch {
	case key == gocui.KeyTab:
		tab = true
	case ch != 0 && mod == 0:
		v.EditWrite(ch)
	case key == gocui.KeySpace:
		v.EditWrite(' ')
	case key == gocui.KeyBackspace || key == gocui.KeyBackspace2:
		v.EditDelete(true)
	case key == gocui.KeyDelete:
		v.EditDelete(false)
	case key == gocui.KeyInsert:
		v.Overwrite = !v.Overwrite
	case key == gocui.KeyEnter:

		if line := v.ViewBuffer(); len(line) > 0 {
			GetLine(Server.Gui, v)
		} else {
			if c, err := Server.Gui.View(Server.CurrentChannel); err == nil {
				c.Autoscroll = true
			}
		}

		InputHistory.Current()

		// v.EditNewLine()
		// v.Rewind()

	// case key == gocui.MouseMiddle:
	// nextView(Server.Gui, v)
	// case key == gocui.MouseRight:

	case key == gocui.KeyArrowDown:
		inHistroy = true

		if line := InputHistory.Next(); len(line) > 0 {
			v.Clear()
			v.SetCursor(0, 0)
			v.SetOrigin(0, 0)

			fmt.Fprint(v, line)
			v.SetCursor(len(v.Buffer())-1, 0)
		}
	case key == gocui.KeyArrowUp:
		inHistroy = true

		if line := InputHistory.Prev(); len(line) > 0 {
			v.Clear()
			v.SetCursor(0, 0)
			v.SetOrigin(0, 0)

			fmt.Fprint(v, line)
			v.SetCursor(len(v.Buffer())-1, 0)
		}
	case key == gocui.KeyArrowLeft:
		v.MoveCursor(-1, 0, false)
	case key == gocui.KeyArrowRight:

		cx, _ := v.Cursor()
		line := v.ViewBuffer()

		// logger.Logger.Println(len(line), cx)
		// logger.Logger.Println(spew.Sdump(line))

		// if cx == 0 {
		// v.MoveCursor(-1, 0, false)
		if cx < len(line)-1 {
			v.MoveCursor(1, 0, false)
		}

	case key == gocui.KeyCtrlA:
		v.SetCursor(0, 0)
		v.SetOrigin(0, 0)
	case key == gocui.KeyCtrlK:
		v.Clear()
		v.SetCursor(0, 0)
		v.SetOrigin(0, 0)
	case key == gocui.KeyCtrlE:
		v.SetCursor(len(v.Buffer())-1, 0)
	case key == gocui.KeyCtrlLsqBracket:
		// logger.Logger.Println("word...")
	}

	if !inHistroy {
		// InputHistory.Current()
	}

	if !tab {
		// logger.Logger.Print("CALL\n")

		inCacheTab = false
		cacheTabSearch = ""
		cacheTabResults = []string{}
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

1 participant