guardian / scribe

DEPRECATED: A rich text editor framework for the web platform
http://guardian.github.io/scribe/
Apache License 2.0
3.51k stars 245 forks source link

new Selection() appears to not be atomic #451

Open nedrocks opened 8 years ago

nedrocks commented 8 years ago

If using logging or debugging within a keydown event while using scribe, the selection object does not appear to maintain its state correctly. This is not a major issue, but confusing none the less.

To reproduce the issue, add an event listener for the scribe event in a plugin (e.g.):

scribe.el.addEventListener('keydown', function(evt) {
  var lastSelection = new scribe.api.Selection();
  console.log(lastSelection.range.collapsed);
  console.log(lastSelection.range);
});

Now, select a block of text within the same span (1 or more characters) and type any key that modifies the state (i.e. forces an input event to fire.) Note that the output should looks something like:

false <---- this is lastSelection.range.collapsed, which is correct

{
  collapsed: true                        <----- Wait what???
  commonAncestorContainer: text
  endContainer: text
  endOffset: 6
  startContainer: text
  startOffset: 6
  ...
}   
rrees commented 8 years ago

I think the API just wraps document.createRange so this might be true depending on how that operation works.