knqyf263 / pet

Simple command-line snippet manager
MIT License
4.54k stars 230 forks source link

Enhance parameter selection #162

Closed ofey404 closed 9 months ago

ofey404 commented 3 years ago

Issue #, if available:

Description of changes:

Add a keyboard shortcut ^U to clear selected parameter in parameter expanding view. Useful when you set a default value, but don't like it. You can quickly kill it and replace with things you like.

Also simplified title of each parameter view.

For example, a parameter like <Name=DefaultValue>

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

RamiAwar commented 9 months ago

I think the real issue behind this is the fact that you can't use typical text editing commands like: Ctrl+Backspace to delete everything until beginning of line Alt+Arrows to jump words

etc.

I also believe gocui supports creating a custom 'editor', something like this, which we could then use to add these natural text editing shortcuts and fix this issue and more!

Will add this to the backlog with medium prio

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)
        }
    ...
}

This ends up being a lot less code and more explicit in terms of what it's doing imo!

https://github.com/knqyf263/pet/issues/249

I'll probably pick this up a bit later, so let me know if you're interested in doing it instead 😏