Giter VIP home page Giter VIP logo

Comments (7)

jroimartin avatar jroimartin commented on May 12, 2024

Can you confirm if it only happens with lines that have been manually written in editable Views?

If so, it's closely related to #60 and should be fixed once that issue is closed. On the other hand, rewriting the edition mode is in progress and (hopefully) will be merged soon.

from gocui.

kkellner avatar kkellner commented on May 12, 2024

Confirmed -- this is only happening with view's that have editors attached.

FYI, my use case is creating a "field widget" to enter 1 line of short text, like a input field on a web page. It will have a label, a fieldName and a maxLength. This will create two views, 1 that will contain the field label and another 1 row view that will be used for the field entry text.

I wrappered the exiting editor to handle the complex part of editing, but my wrapper simple ignores up/down arrows and prevents text beyond maxLength for the field. This is also why the other enhancement request to allow a zero frame view. Let me know if I'm making this too complex and if there is a better way to do this.

from gocui.

jroimartin avatar jroimartin commented on May 12, 2024

What about doing it this way?

https://gist.github.com/jroimartin/3b2e943a3811d795e0718b4a95b89bec

from gocui.

jroimartin avatar jroimartin commented on May 12, 2024

Please, take into account that I did several simplifications, but should be enough to get an idea :)

from gocui.

kkellner avatar kkellner commented on May 12, 2024

Your example is pretty close, however it doesn't allow for arrow keys for editing text already typed into the field. My version used a wrapper around the DefaultEditor to do any special processing on keystrocks, then pass them onto the DefaultEditor as I didn't want to deal with the complexity of processing the arrow keys, insert, etc. Below was my func... a bit ugly with debug code in. Your solution was cleaner -- if it could handle the full editing of the field.

func (w *MyEditor) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
lineValue, _ := v.Line(0)
lineValue = strings.Replace(lineValue, "\x00", "", -1)
currentSize := len(lineValue)
atMax := false
if currentSize >= w.MaxFieldSize {
atMax = true
}
fmt.Printf("\n[%v], currentSize:%v atMax:%v ", lineValue, currentSize, atMax)

switch {
case key == gocui.KeyArrowRight:
x, _ := v.Cursor()
fmt.Printf("\nx:%v", x)
if x < currentSize {
w.baseEditor.Edit(v, key, ch, mod)
}
case key == gocui.KeyArrowLeft:
fallthrough
case key == gocui.KeyBackspace || key == gocui.KeyBackspace2:
fallthrough
case key == gocui.KeyDelete:
fallthrough
case key == gocui.KeyInsert:
w.baseEditor.Edit(v, key, ch, mod)
case key == gocui.KeyEnter:
// v.EditNewLine()
case key == gocui.KeyArrowDown:
// v.MoveCursor(0, 1, false)
case key == gocui.KeyArrowUp:
// v.MoveCursor(0, -1, false)
default:
if !atMax {
//fmt.Printf("key:[%v] ch:[%v]", key, ch )
w.baseEditor.Edit(v, key, ch, mod)
}
}

}

from gocui.

jroimartin avatar jroimartin commented on May 12, 2024

Yes, I tried to keep the snippet as simple as possible and focus on how to create widgets and so on. Definitely, the new edition mode should make easier to customize this kind of things.

from gocui.

jroimartin avatar jroimartin commented on May 12, 2024

Fixed via 2677ad0. Can you check? :)

from gocui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.