Undo, redo, code block evaluation in TextView

Dear all,

I tested the possibility of doing something similar in SuperCollider using WebView and TextView after watching the video in the following post:

I do not know enough about javascript and real time video effect using HTML, CSS and JS. But it seems to work:

https://www.dropbox.com/scl/fo/iu12iksk77bx0ntcuzqzz/h?rlkey=echp2pkntvk1df99pytrig2bv&dl=0

However, I could not do the following in TextView

  • undo
  • redo
  • code block parsing and evaluation by cmd/ctrl + enter

Is there a way to implement these features?

1 Like

https://doc.sccode.org/Classes/TextView.html#-enterInterpretsSelection

In Linux, ctrl-z does undo and shift-ctrl-z does redo. So if you’re not getting undo/redo, it’s not SC’s fault.

hjh

1 Like

Thank you!

Changing text size and colour using a routine with less than 0.25 seconds prevents undo and redo on my machine. I think sclang needs time to remember the text change.

However, the following code cannot be evaluated by cmd/ctrl + enter

(
1
+ // evaluate this block by pressing cmd/ctrl + enter after placing the cursor on this line.
2
)

although using .enterInterpretsSelection_(true); as follows:

(
w = Window().front;
t = TextView(w.asView, w.asView.bounds.insetBy(0, 0))
	.focus(true)
    .enterInterpretsSelection_(true);
)

(
w = Window().front;
t = TextView(w.asView, w.asView.bounds.insetBy(0, 0))
	.focus(true);
t.enterInterpretsSelection = true;
)

(
w = Window().front;
t = TextView(w.asView, w.asView.bounds.insetBy(0, 0))
	.focus(true);
t.enterInterpretsSelection_(true);
)

Is this a bug?

Hm, what would be the correct behavior of “undo,” if you’re making rapid programmatic changes? To undo the last change of any sort, or to undo the user’s latest interactive change? The former would be technically easy but probably not meaningful to the user; the latter would be harder I guess.

The identification of paren-blocks is an editor feature, and TextView isn’t a full-featured code editor. It should be possible to write a response function in sclang to find the code boundaries and interpret.

hjh

1 Like