UndoManager API

18 Sep 2019


heycam, drousso, sanketj, grisha_, Mustaq, Ahmed, whsieh, rniwa, megan
Devin Rousso


RSSAgent: Meeting: UndoManager API

RRSAgent Meeting: UndoManager API

RRSAgent Scribe: Devin Rousso

RRSAgent ScribeNick: drousso

<scribe> Meeting: UndoManager API

<scribe> Scribe: Devin Rousso

<scribe> ScribeNick: drousso

RRSAgent create minutes

megan: system apps dont have access to these functions
... system apps have hidden contenteditable

(oops, I meant web apps, not system apps, for the last message)

megan: platforms that have keyboards can do undo/redo with command/control Z/Y
... without a keyboard, systems usually have gestures to allow for undo
... but no way for web apps to know what these gestures are to enable undo/redo in content rich editors
... on macOS, anything in Edit menu or triple-tap (examples) wouldn't notify the web content
... API would allow interactive web applications to undo/redo more easily
... proposal also allows for multiple undo/redo stacks
... UndoItem has `undo`/`redo` functions and a `label` string for displaying (e.g. Edit menu) to inform user
... UndoManager has a "stack" of items which can be accessed `item(n)`, as well as a current `position` and a total `length`
... undo is "below" `position`, redo is "above"
... UndoManager able to add items to the top and undo/redo the item at `posiiton`
... extend element to create an `undoManager` per-element
... `undoScope` defines the scope for `undoManager`, where items would crawl up the tree to find the closest `undoScope`
... ability to coalesce/merge items in the stack, so that items can individually be put onto the undo stack, but can be done all at once during undo/redo
... set via a `merge` flag on each item

whsieh (prepares demo)

whsieh (demo of drawing text on an iPad, and explaining that each stroke is added to the undo manager, and undo/redo is coalesced for strokes in quick succession)

whsieh (demo/explanation of how CodeMirror uses a hidden `contenteditable` to handle modifications, and how this doesn't work well with Edit > Undo/Redo)

whsieh (continued demo showing how CodeMirror could take advantage of an UndoManager to let CodeMirror properly handle Edit > Undo/Redo, including setting the label)

<whsieh> https://rniwa.github.io/undo-api/

<whsieh> https://whsieh.github.io/UndoManager/

jyasskin can the label match languages with the system?

whsieh seems like a similar problem to any other API vended from the DOM

whsieh not a new problem to UndoManager

rniwa would be weird for a chinese/japanese user to see a language that was in english

whsieh cocoa platforms solved this by making the property names "localizedLabel" so it's obvious to the developer

<grisha_> queue

rniwa alternative approach that couldve been taken would be to have a limited list of labels that are hardcoded, but that wouldnt be extensible/flexble

smaug how does this integrate with existing undo manager? Firefox has internal undo manager. is this API on top of browser, or can user agent add items to undo stack?

rniwa browser looks at currently active focusable area and walks up DOM tree to find first ancestor with `undoManager` and adds items to that

rniwa callbacks in that case are browser "functions"

heycam this is a bit different than other cases of page text being used in chrome, as it's possibly the first time it's used in conjunction with system text

whsieh that is a bit odd

heycam what's the advantage of merging being in the API vs having the developer doing it themselves?

whsieh mainly for convenience

rniwa browser could do its own things, so the only way to be able to merge with the browser is to have an API level merge since the browser created the item

heycam so both system and user items are present in the list?

whsieh rniwa yes

rniwa right now, execCommand cant really be used because of how it affects the undo/redo stack, which isn't otherwise able to be affected by script (without this proposal)

whsieh if you want to augment/override an existing execCommand, you might want to replace the default label

NavidZ_ does the crawl up the ancestor keep going if the stack is empty?

whsieh no, we want to stop if you reach an ancestor that has an undo manager but its stack is empty

whsieh otherwise, if you kept undoing it would suddenly start undoing things elsewhere on the page

sanketj is the label idea a concept that's from the mac?

whsieh it exists on macos and ios

sanketj other apps can customize that?

whsieh yes, native apps can customize it

rniwa this label is important for accessibility, like for cases where the user cant see what UI is on the screen

sanketj what about pages that already have the concept of an undo manager?

rniwa ideally, those pages would sync with the undo manager

sanketj you'd have to plug into using this UndoManager API in order to do this functionality?

rniwa yes, since the OS itself doesn't have such a primitive, so there needs to be an API

danclark what's the fragility of this if the page has been modified since an undo function was created?

danclark like if some scripted action modifies the state of the DOM after an undo item was added

whsieh this a problem right now if you built your own undo stack system

danclark old edge HTML would try to apply something reasonable to undo/redo items as a result of scripted actions

rniwa that assumes that scripted actions are as a result of some interaction, which isn't the case here

rniwa we could add something in the future that could do that sort of "house keeping"

dmurph would be cool if undo state could be serialized/saved, so you could come back later and undo a bunch of stuff

dmurph but it seems like that isn't completely possible due to the browser items

whsieh we could probably serialize most regular text actions, but there are some actions that wouldn't be serializable

rniwa you could use a MutationObserver to see what the browsers doing (at least for user commands), and serialize it yourself to save/restore

dmurph potential abuse scenarios? something spamming the stack?

whsieh probably want to gate this on some sort of user interaction/activation

whsieh most actions are probably as a result of a user action

whsieh might also want some maximum list of items in the list, as without that you may run into memory/performance issues

dmurph there could be a conflict between serializing for save/restore and having a limit on the number of items

whsieh thats true, but it's a potential tradeoff that we'll have to make and we'll see if it's really requested

grisha_ setting a restriction may have problems for huge documents with things like find and replace

whsieh you could merge them all together though

johannas i feel like we'd likely only put one item on the undo stack, so we get the callbacks, but we'd still maintain our own stack

johannas collaborative editing might cause the undo stack to grow or shrink from the other person

johannas and using the undo stack may not work nicely with preserving the local undo stack between people who are collaborating

johannas gating behind a user gesture may prevent collaborative editing undo/redo since they can happen whenever

whsieh that is still being considered

whsieh adding a new undo would remove all existing redo items

sanketj it seems like what he really wants is a way of setting the undo/redo label independently of adding/removing items from the stack

rniwa that would be harder to do at a native level

johannas this proposal is nice because modals wouldn't be able to break/pollute the main undo stack since you can scope it to a node

<jyasskin> ack mustaq (for last message)

mustaq (sorry i missed this)

rniwa whatever the browser does right now, this wouldn't affect that

musaq (for last message) would cross origin navigation keeps the undo/redo stack?

rniwa this hasn't been defined in the spec yet

birtles is there interop between browsers for what gets added by the browser to the undo/redo stack? is there a way to check?

rniwa undo/redo behavior is really dependent on the platform, and probably can't be spec

birtles can a web developer inspect and figure out what is getting added?

rniwa you may be able to intercept various events and check the stack or the DOM

birtles worried about adding a redundant item because the system already added it

rniwa we could add an undo "change" event that would be fired (i missed the rest)

birtles are values on the undo item preserved?

whsieh yes, but we should also probably add some sort of `data` that can be held by the item

heycam on platforms where form control scoping isn't per-page, would form control items automatically create their own scope?

rniwa the spec could be made to allow the platform to do different things

whsieh is it difficult to add this functionality?

heycam possibly not

whsieh WebKit has the opposite problem, where everything is global, so WebKit has to do the work to split it up

heycam the API should probably be flexible between platforms then

rniwa yes, we agree

christianliebel what happens if i use an english OS but the app is a different language? what would the label do then?

christianliebel what's the "interaction" between the system, app, and page's languages?

christianliebel what about if any of those are changed in the middle of editing?

whsieh this may also be a problem on macOS right now too

christianliebel having a set of predefined operations may be useful

whsieh that would help the editor case, but we'd like this to be powerful enough to handle feasibly anything that would want to be undoable on the web

rniwa labeling undo/redo doesn't appear to be a macOS only thing either

<Zakim> jyasskin, you wanted to talk about how abuse only hurts yourself

jyasskin abuse seems like it only would hurt the page that's doing the abuse

whsieh that could potentially hurt other tabs too, like having a huge undo stack and switching between tabs

RRSAgent make logs public

Summary of Action Items

Summary of Resolutions

[End of minutes]

Minutes manually created (not a transcript), formatted by David Booth's scribe.perl version 1.154 (CVS log)
$Date: 2019/09/18 16:24:56 $

Scribe.perl diagnostic output

[Delete this section before finalizing the minutes.]
This is scribe.perl Revision: 1.154  of Date: 2018/09/25 16:35:56  
Check for newer version at http://dev.w3.org/cvsweb/~checkout~/2002/scribe/

Guessing input format: Irssi_ISO8601_Log_Text_Format (score 1.00)

Succeeded: s/birtles/musaq (for last message)/
Succeeded: s/birtles/mustaq (for last message)/
Succeeded: s/limiting abuse/abuse/
Present: heycam drousso sanketj grisha_ Mustaq Ahmed whsieh rniwa megan
Found Scribe: Devin Rousso
Found ScribeNick: drousso

WARNING: No "Topic:" lines found.

WARNING: No meeting chair found!
You should specify the meeting chair like this:
<dbooth> Chair: dbooth

WARNING: No date found!  Assuming today.  (Hint: Specify
the W3C IRC log URL, and the date will be determined from that.)
Or specify the date like this:
<dbooth> Date: 12 Sep 2002

People with action items: 

WARNING: Input appears to use implicit continuation lines.
You may need the "-implicitContinuations" option.

WARNING: No "Topic: ..." lines found!  
Resulting HTML may have an empty (invalid) <ol>...</ol>.

Explanation: "Topic: ..." lines are used to indicate the start of 
new discussion topics or agenda items, such as:
<dbooth> Topic: Review of Amy's report

WARNING: IRC log location not specified!  (You can ignore this 
warning if you do not want the generated minutes to contain 
a link to the original IRC log.)

[End of scribe.perl diagnostic output]