Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selection constructor should accept ranges array #3822

Closed
Reinmar opened this issue Sep 19, 2016 · 5 comments
Closed

Selection constructor should accept ranges array #3822

Reinmar opened this issue Sep 19, 2016 · 5 comments
Labels
intro Good first ticket. package:engine type:feature This issue reports a feature request (an idea for a new functionality or a missing option). type:improvement This issue reports a possible enhancement of an existing feature.
Milestone

Comments

@Reinmar
Copy link
Member

Reinmar commented Sep 19, 2016

Cause, currently I have to do this:

const sel = new Selection();
sel.addRange( range );

Which could be simplified.

@ma2ciek
Copy link
Contributor

ma2ciek commented Apr 10, 2017

As I talked with @Reinmar, we'll create a new static function rather than change the constructor, so there'll be no need to rewrite existing code.

Usage

const sel = Selection.createFromRanges( [ range1, range2 ] );
 // And with isLastBackward set to true:
const sel2 = Selection.createFromRanges( [ range1, range2 ], true );

Note

The Selection.createFromRanges uses the Selection#setRanges under the hood, so it's firing change event for now which is not needed I suppose.

@Reinmar
Copy link
Member Author

Reinmar commented Apr 10, 2017

The Selection.createFromRanges uses the Selection#setRanges under the hood, so it's firing change event for now which is not needed I suppose.

It's not needed but it changed nothing because you can't listen on it :D

As I talked with @Reinmar, we'll create a new static function rather than change the constructor, so there'll be no need to rewrite existing code.

TBH, I think I might've changed my mind. Range() does accept two positions and Position() does accept root and path. So, since range + direction is the most typical way of creating a selection I guess it could be the constructor's option.

Why I initially thought about moving it to a separate method was that I wasn't sure whether this is an identical case to Range and Position because the view selection can also be a fake one (so that's like another type of selection so why would the constructor handle just one). But... I've just completely overcomplicated this.

@ma2ciek
Copy link
Contributor

ma2ciek commented Apr 10, 2017

Ok, it makes sense, so I'll move this code to the constructors :D

@ma2ciek
Copy link
Contributor

ma2ciek commented Apr 10, 2017

I pushed the corrected version which still uses setRanges(). But now setRanges is reassigning _ranges and _lastRangeBackward and fires change event which is unnecessary. Maybe we can use the default parameters in the constructor function + simple range instanceof checks at the end?

@Reinmar
Copy link
Member Author

Reinmar commented Apr 10, 2017

Let's discuss this under ckeditor/ckeditor5-engine#918.

Reinmar referenced this issue in ckeditor/ckeditor5-engine Apr 11, 2017
Feature: Allow passing ranges to the selection constructors (in the model and in the view). Closes #600.
@mlewand mlewand transferred this issue from ckeditor/ckeditor5-engine Oct 9, 2019
@mlewand mlewand added this to the iteration 10 milestone Oct 9, 2019
@mlewand mlewand added intro Good first ticket. status:confirmed type:improvement This issue reports a possible enhancement of an existing feature. type:feature This issue reports a feature request (an idea for a new functionality or a missing option). package:engine labels Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
intro Good first ticket. package:engine type:feature This issue reports a feature request (an idea for a new functionality or a missing option). type:improvement This issue reports a possible enhancement of an existing feature.
Projects
None yet
Development

No branches or pull requests

3 participants