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

Refactor document delta handling for v1.2 #1819

Merged
merged 46 commits into from
May 21, 2015
Merged

Refactor document delta handling for v1.2 #1819

merged 46 commits into from
May 21, 2015

Conversation

nightwing
Copy link
Member

this is continuation of #1745

todo

  • review undomanager changes, try to remove unnecessary copying of delats
  • fix delta validation error in autocompletion popup or disable validation

aldendaniels and others added 30 commits January 1, 2014 00:41
Refactor delta handling code to:

- Combine the "insertText" and "insertLines" delta types into a single
"insert" delta type

- Combine the "removeText" and "removeLines" delta types into a single
"remove" delta type

- Make all document mutations in a single applyDelta function.

- Add basic delta validation (more needed . . . see TODOs)

- Rework anchor logic to handle new delta types (also simplified)

- Rename "insert()" to "insertText()" and "remove()" to "removeText()"

- Rename "insertLines()" to "insertFullLines()" and "removeLines()" to
"removeFullLines()"

See related issue for more information. All tests are passing and the
changes appear functional under preliminary testing, but careful review
and testing will be necessary.
This seeks to keep the public API in-tact while improving method names
within ace by keeping the old methods as wrappers around the new
better-named methods.

For example, document.insert() now simply calls document.insertText()
and warns the caller via a console.log() that they are using a
deprecated method.

I've also updated the coding style of my changes (where I noticed
discrepancies) to match the rest of Ace.
Both were introduced in 2e6f127.
console.warn makes better sense than console.log and matches similar
warnings in ace (see gutter.js for example).
2e6f127 slowed down the application of
deltas that only affect a single line. The slow-down, though trivial for
a single line, is significant for operations than separately modify
thousands of rows (such as indenting a large document).

This commit speeds up single-line deltas by avoiding unnecessary calls
to splitLine() and joinLineWithNext().
This makes it possible to break out helper functions without exposing
them to the rest of the document class. Also, long term, we may want to
have a stand-alone test suite for applyDelta, so it makes sense in its
own file.

All other changes involve syntax corrections (some syntax issues were
mine, others pre-existed) to make the documentation compilation work.
Since .apply() can't handle more than 65535 parameters, splice.apply()
is brittle. It's also hard to read. This replaces splice.apply() calls
throughout ace code with lang.spliceIntoArray().
Matches previous naming convention.
Avoids an extra $split call.
Also brings back the functionality where large deltas are split into
smaller deltas so that .splice.apply() calls will work.
This uncovered the fact that until now delta.range had not always been a
Range object. This inconsistency has been resolved by my changes in
mirror.js.
Set it to true in insertInLine/removeInLine.

Also sped up indent/dedent by using insertInLine and removeInLine.
Stores single-line delta content as .text instead of .lines in undo
history. This is done without modifying the original delta object in
case the caller still retains a handle to the original.
- Fix unconventional '{' formatting
- Reformat `UndoManager` changes
- Revert change from `insertInLine` to `insert` in text.js
This should be faster since we don't have to re-initialize the helper
functions each time Anchor.onChange is fired.
Refactor document delta handling
Conflicts:
	lib/ace/line_widgets.js
Conflicts:
	lib/ace/document.js
	lib/ace/editor.js
	lib/ace/undomanager.js
Conflicts:
	lib/ace/anchor.js
	lib/ace/keyboard/vim/maps/operators.js
Conflicts:
	build
	lib/ace/document.js
	lib/ace/editor.js
@lennartcl
Copy link
Contributor

@nightwing LGTM, appears to work well. I see there is still an open action item above? Also:

  • make sure this works with collab and aceterm and stuff (not strictly related to the ace project, but this is something to consider)
  • fix merge conflict

@nightwing nightwing changed the title [wip] v1.2 Refactor document delta handling for v1.2 May 21, 2015
@lennartcl
Copy link
Contributor

v-1.2.0-pre it is!

lennartcl added a commit that referenced this pull request May 21, 2015
Refactor document delta handling for v1.2
@lennartcl lennartcl merged commit 0a3b002 into master May 21, 2015
@lennartcl lennartcl deleted the v-1.2 branch May 21, 2015 09:15
@aldendaniels
Copy link
Contributor

@lennartcl, @nightwing - Great to see this merged!

@nightwing - Just a heads-up in case there's some loose ends here - looks like you disabled the delta validation in ad54d2c since it "it breaks autocompletion popup". If the auto-complete popup is sending invalid deltas, then silencing the validation is probably not the long-term answer. :)

If you do turn off validation, you'll want to also remove the doNotValidate parameter to avoid confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants