-
Notifications
You must be signed in to change notification settings - Fork 40
T/1555: Expose Position, Range and Selection factories. #1585
Conversation
…teFromPosition( position ) to clone position.
…mParentsAndOffsets().
# Conflicts: # src/model/operation/transform.js
Remaining engine imports (source code - not tests) from other packages (exluding core & editors): import bindTwoStepCaretToAttribute from '@ckeditor/ckeditor5-engine/src/utils/bindtwostepcarettoattribute';
import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
import Observer from '@ckeditor/ckeditor5-engine/src/view/observer/observer';
import ClickObserver from '@ckeditor/ckeditor5-engine/src/view/observer/clickobserver';
import DomEventObserver from '@ckeditor/ckeditor5-engine/src/view/observer/domeventobserver';
import MouseObserver from '@ckeditor/ckeditor5-engine/src/view/observer/mouseobserver';
import DomEventData from '@ckeditor/ckeditor5-engine/src/view/observer/domeventdata';
import DomConverter from '@ckeditor/ckeditor5-engine/src/view/domconverter';
import { attachPlaceholder } from '@ckeditor/ckeditor5-engine/src/view/placeholder';
import { transformSets } from '@ckeditor/ckeditor5-engine/src/model/operation/transform';
import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
import { downcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
import { upcastElementToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import { upcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import LivePosition from '@ckeditor/ckeditor5-engine/src/model/liveposition';
import LiveRange from '@ckeditor/ckeditor5-engine/src/model/liverange'; |
* const otherSelection = writer.createSelection(); | ||
* const selection = writer.createSelection( otherSelection ); | ||
* | ||
* // Creates selection from the given document selection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line bothers me - I'd wrote this as:
const documentSelection = doc.selection;
const selection = writer.createSelection( documentSelection );
I reviewed how plugins use this API (I will check the engine on Monday) and... wow, that's huge! Good job @jodator! What I like is that usually What I do not like is the way how the selection is created from a position, for instance:
I think we should have something like
The construction
|
# Conflicts: # src/model/model.js # src/view/position.js # tests/model/position.js # tests/view/position.js
Nah, just use |
All engine tests passes locally - Right now engine requires parapraph which requires engine which requires paragraph .... hence the errors on Travis 😞 |
# Conflicts: # src/model/model.js
src/view/documentselection.js
Outdated
@@ -35,19 +35,19 @@ export default class DocumentSelection { | |||
* const selection = new DocumentSelection(); | |||
* | |||
* // Creates selection at the given range. | |||
* const range = new Range( start, end ); | |||
* const range = writer.createSelection( start, end ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const range = writer.createSelection( start, end );
There is something wrong here.
I notice it reviewing engine code. And I need to say that it is a little bit messy now. We have
I think it is good that this method is long. It should be used only in special cases, so the long name properly suggestion that this should not be your first choice.
As mentioned before, I prefer
That's a good idea, but we can keep it as internal engine method at the moment.
We should not expose
I think we can keep it the way it is now. Users are able to create view writers whenever when need it and I think that better docs are not a good enough reason to add Also, these methods should be added to |
@pjasiun again - many methods in |
I think that I've done my best to overcome this - I've just put |
Suggested merge commit message (convention)
Type: Implement a builtin Position, Range and Selection factories. Closes ckeditor/ckeditor5#4427.
BREAKING CHANGE: The model
Position.createAt()
was removed from public API. Usewriter.createPositionAt()
instead.BREAKING CHANGE: The model
Position.createAfter()
method was removed from public API. Usewriter.createPositionAfter()
instead.BREAKING CHANGE: The model
Position.createBefore()
method was removed from public API. Usewriter.createPositionBefore()
instead.BREAKING CHANGE: The model
Position.createFromPosition()
method was removed. Usewriter.createPositionAt( position )
to create a new position instance.BREAKING CHANGE: The model
Position.createFromParentAndOffset()
method was removed. Usewriter.createPositionAt( parent, offset )
instead.BREAKING CHANGE: The model
Range.createIn()
method was removed from public API. Usewriter.createRangeIn()
instead.BREAKING CHANGE: The model
Range.createOn()
method was removed from public API. Usewriter.createRangeOn()
instead.BREAKING CHANGE: The model
Range.createFromRange()
method was removed from public API.BREAKING CHANGE: The model
Range.createFromParentsAndOffsets()
method was removed from public API.BREAKING CHANGE: The model
Range.createFromPositionAndShift()
- method was removed from public API.BREAKING CHANGE: The model
Range.createCollapsedAt()
- removed method was removed. Usewriter.createRange( position )
to create collapsed range.BREAKING CHANGE: The model
Range.createFromRanges()
method was removed from public API.BREAKING CHANGE: The view
Position.createAt()
was removed from public API. Usewriter.createPositionAt()
instead.BREAKING CHANGE: The view
Position.createAfter()
method was removed from public API. Usewriter.createPositionAfter()
instead.BREAKING CHANGE: The view
Position.createBefore()
method was removed from public API. Usewriter.createPositionBefore()
instead.BREAKING CHANGE: The view
Position.createFromPosition()
method was removed. Usewriter.createPositionAt( position )
to create a new position instance.BREAKING CHANGE: The view
Range.createIn()
method was removed from public API. Usewriter.createRangeIn()
instead.BREAKING CHANGE: The view
Range.createOn()
method was removed from public API. Usewriter.createRangeOn()
instead.BREAKING CHANGE: The view
Range.createFromRange()
method was removed from public API.BREAKING CHANGE: The view
Range.createFromPositionAndShift()
- method was removed from public API.BREAKING CHANGE: The view
Range.createFromParentsAndOffsets()
method was removed from public API.BREAKING CHANGE: The view
Range.createCollapsedAt()
- removed method was removed. Usewriter.createRange( position )
to create collapsed range.Additional information
mgit.json
on branch:This PR might close ckeditor/ckeditor5#4426 as well as I had to base this PR on
t/1554
branch. Might require adding some packages with ckeditor/ckeditor5#4426 only changes though.Brief summary of changes:
Position
,Range
andSelection
imports (model/view) were removed from packages. AFAIR. Remaining engine imports. Most packages has now engine only as adevDependency
inpackage.json
- ps.: I've sorted somepackage.json
entries cause my eyes were hurt.new Position()
andPositon.createAt()
usages in examples and were replaced bywriter.createPositionAt()
in most cases - some havemodel.createPostionAt()
examples - where it had sense only. So thewriter.createFoo()
methods are preferred in the docs. AFAICS I've only leftnew Position()
examples in thesrc/dev-utils/
examples as they are low-level anyway.element instanceOf Element
and similar checks from packages (not engine) and usedsupsect.is( 'element' )
checks instead.writer
context (model.change()
blocks)5 I've added:
schema.createContext()
method to create a context without importSchemaContext
model.createBatch()
method for those 2 cases werenew Batch()
was needed (obviously I do not createdwriter.createBatch()
).Things to discuss:
.clone()
andLiveRange.fromPosition()
changes as in some cases methods could have bothPosition
orLivePosition
and I wasn't able to catch them all. But:Position.createFromPosition()
- it isLivePosition.fromPosition()
andlivePos.toPosition()
now - I've replaced it were it was obious. Also you can copy position byPosition.createAt( position )
.The
writer.createPositionFromPath()
is tooooo long IMHO. I'd call thatwriter.createPosition()
- similarly towriter.createRange()
.Range copy - right now we do not have
writer
methods for:Range._createFromRange()
- it could be exposed aswriter.createRange( range )
alternative.Range._createFromRanges()
- this might be as well a utility function as it is only used in about 5 places in the engine.I had minor conceputal issues with rewriting the
new DocumentSelection()
examples - mostly in thecreateSeleciton()
docs. Does public API should/or will expose creator for this? Or we just remove lines about that?I've created factory methods on
model
and then in thewriter
I use model instance. Obviously I've linked it properly (hope so) in docs. Now, for theview
theDowncastWriter
does not have a reference to the view so I could not reuse it. Probably a minor change to passview
to the writer but I wanted to ask you guys about such change. Right now the code is duplicated forview
anddowncastWriter
.