gWidgets2 icon indicating copy to clipboard operation
gWidgets2 copied to clipboard

`append=FALSE` and cursor placement/autoscrolling for `insert.GText`

Open landroni opened this issue 10 years ago • 2 comments

Currently doing insert(gtext_obj, "asdf") will invariably prepend/append the text to existing text already in the widget. It would be useful to be able to replace existing text via an append=FALSE argument. Alternatively you could make the where= argument to take the values c("end", "beginning", "at.cursor", "replace").

Moreover, after a text is being inserted the window is scrolled to the end of the widget. Sometimes it would be better if the cursor ended up actually at the beginning of the widget. So how about adding a cursor.pos=c("default", "end", "beginning")? With "default" being the current behaviour, "end" placing the cursor and scrolling the window to the end of the text widget, and "beginning" placing the cursor and scrolling the window to the beginning of the text widget.

landroni avatar Jul 09 '14 08:07 landroni

This is possible. When you say replace are you replacing the entire text of just the (possibly) currently selected text? The entire text can be reset via svalue<-.

As for cursor position, the options could be beginning, end or no scroll. But it might be better to expose the scrolling method. Not sure what to call it though. There isn't an obvious generic method name is there? (In Gtk is it scroll_to_iter, in tk it is see (which isn't great). I'm tempted to make a private obj$scrollto(where=c("end", "beginning", "???")) method and see if there is demand for more.

jverzani avatar Jul 15 '14 01:07 jverzani

As per https://github.com/jverzani/gWidgets2/issues/51, if I replace text via svalue<-, then I lose formatting. And I cannot scroll the widget as needed (to the beginning). So what I currently do is:

    svalue(t_descr) <- ""
    insert(t_descr, descr.out, font.attr=list(family="monospace"))

Which works, but is suboptimal. So an insert(..., append=FALSE) or similar could be useful. But if #51 gets fixed and a scrolling method is added, maybe this would no longer be needed.

As for scrolling, a obj$scrollto(where=c("end", "beginning", "no.scroll")) method sounds useful and intuitive to me. BTW, are such methods officially documented in the help pages (or should they be?), or are they hidden implementations?

landroni avatar Jul 15 '14 08:07 landroni