Giter Site home page Giter Site logo

selection-api's Introduction

selection-api

Selection API Specification defines APIs for selection, which allows users and authors to select a portion of a document or specify a point of interest for copy, paste, and other editing operations.

selection-api's People

Contributors

afbarstow avatar aroben avatar autokagami avatar ayg avatar bangseongbeom avatar cladis avatar darobin avatar deniak avatar domenic avatar dontcallmedom avatar ehsan avatar foolip avatar janiceshiu avatar johanna-hub avatar marcoscaceres avatar plehegar avatar reinmar avatar rniwa avatar sanketj avatar saschanaz avatar siusin avatar vivienlacourba avatar ylafon avatar zhang-junzhi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

selection-api's Issues

Selection events for text controls

The current spec doesn't explain what needs to happen for input and textarea elements when the selection inside them changes. Those selections are not associated with the Selection object for a Document, so we need to handle them somehow.

I think a nice way to extend the current spec to cover this case would be to dispatch selectstart and selectionchange to the input or textarea element itself when the selection inside them changes. The reason why the selectionchange event needs to be dispatched to the element and not the Document is that the web page would otherwise be unable to detect which selection has changed.

Make some arguments optional

In both WebKit and Blink, the arguments of some functions are optional. That includes some nonsensical cases like "void addRange([Default=Undefined] optional Range range);" but also some arguments that have sensible defaults:
collapse's offset argument (0)
extend's offset argument (0)
containsNode's allowPartialContainment argument (false)

setBaseAndExtent also has all optional arguments, but that makes less sense.

Consider making at least the first three cases optional, as it does not seem worthwhile investigating the Web compat impact of making them non-optional.

unsigned long is never negative

The steps for collapse() and setBaseAndExtent include checks for negative numbers, which cannot be true. (These are signed in WebKit/Blink, I guess the steps were just copied.)

Address non-selectable text

At the moment, CSS-generated text is not selectable in most (all?) user agents. It is also possible to make text unselectable via CSS styles. The Selection API should address this somehow.

Possibilities that spring to mind include:

  1. Declare that rendered text should be selectable. (Preferred)
  2. Define the expected behavior (e.g. in addRange() and extend()) when a selection starts at, stops at, or includes non-selectable text.
  3. Add API through which one could query if a given range is selectable.

Add APIs to save/restore selection

Forked from w3c/editing#39.

To summarize:

  1. In order for editors to move the selections temporary, do some work in other regions, then restore the selections back, we need a new APIs.
  2. This APIs not only save all public properties of selections but also internal states as well, so that the selections can really be restored.
  3. There are some details we need to take care of, such as IME uncommitted strings. Usually IME uncommitted strings are committed when the selections are changed. But since IME uncommitted strings are part of the internal selection states, and since we want to restore it later, UA should cancel them on save (or save then move the selection.) Not sure whether this should be spec'ed, just an informative note, or not needed in the spec though.

Should selectionchange be fired when the Range object is directly mutated

If the range object is directly mutated by the user script, should the selectionchange event be fired? This isn't clear in the documentation.

var s = document.getSelection();
var r = document.createRange();
r.selectNode(node1);
s.addRange(r); // selectionchange event should be queued
// -- some time passes --
r.selectNode(node2); // Should another selectionchange event be queued?

support selection.containsNode(obj, true)

Could you please implement selection.containsNode(), as I need to use it or to use something like it for my GoogleTrans gadget, which is on en.wikipedia.org.

This gadget is loaded by 23,000 ids on the English wikipedia.

I have something called selection translation.

You

  1. select small amounts of text (> 500 characters)
  2. put the cursor within the selected text (to avoid annoying popups when you don't want them)
  3. hold the shift key down.

When you do these three things, then a popup happens with the Google translation of the selected text.

In order to know whether the cursor is in the selected text object I use, among other things, the selection.containsNode()

A small clip of the code is below:

/*
if(userSelection.containsNode(children[i],false))
SCselection[i] = true;
else
*/

       if(!SCbIsIE11 && userSelection.containsNode(children[i],true))
       {

          SCselectionarray[i] = new Array();
          SCselectionstart[i] = -1;
          SCselectionend[i] = -1;

          SCAreWordsInSelection(userSelection,SCselectionarray[i],
          children[i],i);

          SCselection[i] = false;
       }
       else
       {

          SCselectionarray[i] = new Array();
          SCselection[i] = false;
          SCselectionstart[i] = -1;
          SCselectionend[i] = -1;
       }

I want to tell you that I never could get userSelection.containsNode(children[i], false) to work. Firefox (and later IE9 and IE10) only worked for userSelection.containsNode(children[i], true)

However, both IE9 and IE10 supported this call. Would you please support the call for IE11, as least in the
userSelection.containsNode(children[i], true) mode. It is very helpful to me.

Otherwise, I cannot support knowing whether the cursor is over the current selection.

Add beforeselectionchange event

Quoting @johanneswilm from w3c/editing#73:

beforeselectionchange has been mentioned a few times. This event should be in the Selection API. If the caret movements intentions are to be moved there, it's important that the beforeselectionchange event contains the user intention (such as: "caret up").

Alternatively the beforeselectionchange event can just have a from-range and a to-range that doesn't need to specify what user intention caused the selection change, and we keep the intended caret movement events the beforeinput.

Clarify association between a selection and its range

"Once a selection is associated with a given range, it must continue to be associated with that same range until this specification requires otherwise."

This paragraph above is vague. It needs to be replaced by detailed conformance requirements saying exactly what to do for particular keystrokes, like we have for backspace/delete/etc.

Define caret behavior around replaced, SVG, and MathML elements

Different browsers currently have different issues with this. The only stub element that they all seem to be able to navigate around are IMGs. Others, such as SVGs or Canvas-elements are only handled correctly in some browsers and not in others. Also, carets should be able to be displayed before, after and in-between non-editable elements and non-editable elements with editable islands.

See also https://bugzilla.mozilla.org/show_bug.cgi?id=873883

And discussion starting in w3c/editing#58 (comment)

Parallel Selection-like object for concurrent editing?

Some apps have concurrent editing support. Since the Selection object represents the current user's selection, we need a parallel way to represent another user's selections.

This would make them much more easily Accessible. Today, browsers can announce changes to the selection object, but they have no easy way to track changes from other users to other areas of the document. A selection-like object for this purpose is one way to do this.

This request comes from the IndieUI WG. It is likely a V2 feature, or possibly needs it's own spec. But I want to make sure it's tracked.

Add Selection.type to the spec

Selection.type appears to be supported in Chrome and used on CKEditor. We should define it. It supports at least "None", "Caret", and "Range" as values.

Clarify selectstart event behaviour

I'm currently implementing selection events for gecko, and I noticed that the selectstart event documentation currently appears to imply that every time that a user changes the selection, a selectstart event should be fired. This is because of the combination of:

When the user agent is about to associate a new range newRange to the selection in response to a user initiated action, the user agent must fire ([DOM4]) an event with the name selectstart [...]

and

If the user makes any modification to a selection, the user agent must create a new range with suitable start and end of the range ([DOM4]) and associate the selection with this new range (not modify the existing range) [...]

This behavior definitely doesn't agree with chrome's implementation (resizing a selection in a textbox with the arrow keys in chrome, for example, doesn't fire selectstart events).

My best guess at the intention of this is that the selectstart event is intended to fire whenever a selection goes from being empty or collapsed to being non-collapsed. This is what I am currently implementing in Bug 571294. The spec should be updated to clarify what the intent is.

What if the underlying range is changed?

Should this spec codify if the range return by selection.getRangeAt(0) is changed, (e.g. insert a node into the range), the selection should change accordingly or not?

Currently, browsers behave differently on this one. Webkit and blink make selection to contain a new range. Gecko changes the selection. I personally think Gecko's behavior is the correct one.

Is Selection.removeAllRanges() and Selection.removeRange(range) doing the same thing?

  • As Selection.removeAllRanges() and Selection.removeRange(range) uses the same statement
    The method must make the context object empty by disassociating its range if the context object's range is range.Otherwise, it must do nothing.

One more point, what is range, in Selection.removeAllRanges() when we are saying if the context object's range is range`.

Add APIs to save/restore selection

Forked from w3c/editing#39.

To summarize:

In order for editors to move the selections temporary, do some work in other regions, then restore the selections back, we need a new APIs.
This APIs not only save all public properties of selections but also internal states as well, so that the selections can really be restored.
There are some details we need to take care of, such as IME uncommitted strings. Usually IME uncommitted strings are committed when the selections are changed. But since IME uncommitted strings are part of the internal selection states, and since we want to restore it later, UA should cancel them on save (or save then move the selection.) Not sure whether this should be spec'ed, just an informative note, or not needed in the spec though.

Specify baseNode/baseOffset/extentNode/extentOffset?

setBaseAndExtent as implemented in WebKit/Blink are related to these. Is the plan to drop the attributes but keep the function? Use counter data from Chrome:
https://www.chromestatus.com/metrics/feature/timeline/popularity/400
https://www.chromestatus.com/metrics/feature/timeline/popularity/401
https://www.chromestatus.com/metrics/feature/timeline/popularity/402
https://www.chromestatus.com/metrics/feature/timeline/popularity/403
https://www.chromestatus.com/metrics/feature/timeline/popularity/406

Based on this dropping the attribute looks doable, but is WebKit going to?

Need a way to get BiDi dir from Range

From MS Office Team:
The Unicode BiDi Algorithm (explained here: http://www.unicode.org/reports/tr9/tr9-31.html) is used by Text Rendering engines to properly display LTR and RTL text together in the same paragraph. In short, each character has a classification (mostly L and R, plus a bunch of neutral types), and the sequence of character classifications is used to determine which runs are displayed as LTR or RTL.

Mostly what I think we would need is the ability to query, for a given character, whether its direction is LTR or RTL after the Unicode BiDi Algorithm has been applied. I don’t know where the best place to put this API would be, perhaps the Range object? Something like this:

Range.getBiDiTextDir() : int
Return value is an enum in the range (LTR, RTL, MIXED), where MIXED is returned when the Range contains both LTR and RTL characters. (The caller would need to try again with a smaller range to get something useful in this case. MIXED would never be returned for a single character.)

I have no idea if this is the best API design but I’m just hoping to get across what would be useful to us.

For context, the reason this is important to us is that while HTML has the concept of “neutral text direction” (whenever the CSS property direction: ltr or direction: rtl is NOT specified), some editors like Word do not. Every run is either marked as LTR or RTL. If we can’t correctly detect the text as it’s being typed, then we may save it incorrectly into the document, and Word will display text direction differently than what the user saw as they were typing in the browser. There are also some performance optimizations we could make around text selection if we knew where in a paragraph the text changed direction, but this is less of a compelling reason than content fidelity.

caret-based selection movement

The selection Api so far doesn't talk about changing the selection when moving the caret.

This will only apply when cE=typing and cE=true are specified, so it may have to go into another document.

If it's not specified anywhere, and browsers choose to implement it different, we won't be sure so we will need to continue to interrupt each key stroke event to check whether the caret may be at the border of an element before letting it do its default action. Then it may be easier to use a hidden textarea for input instead of cE=typing.

Two issues come to mind:

  1. Caret at the end of an inline element

    <p>Hello <i>Austri|a</i></p> ( | = caret)
    

    If the user hits the right-key and then enters a "!", where should that end?

    <p>Hello <i>Austria</i>!|</p> or  <p>Hello <i>Austria!|</i></p> ?
    

    And what is the intermediate step? To the user, these two situations will look the same:

    <p>Hello <i>Austria</i>|</p> and <p>Hello <i>Austria|</i></p>
    

    so it seems it would be reasonable that they will behave the same as well.

  2. It should be ensured that the movement of the caret is the same in all browsers.

    There are some well-known issues with that now, mostly related to the caret "jumping" another character when moving across inline void elements, foreign elements (SVGs) or elements that are specified as being noneditable or the caret not being able to go certain places (such as before one of the before mentioned elements when these are at the start of a block element). In all these cases, I believe it should be specified that these elements should be treated like single characters in relation to caret movement.

Clarify the additions of this spec to GlobalEventHandlers

It seems to me that this spec needs to include the following IDL changes for the event handlers that it adds, something like:

partial interface GlobalEventHandlers {
  attribute EventHandler onselectstart;
  attribute EventHandler onselectionchange;
};

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.