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

Edit session operation #5657

Merged
merged 10 commits into from
Oct 21, 2024
Merged

Edit session operation #5657

merged 10 commits into from
Oct 21, 2024

Conversation

marinsokol5
Copy link
Contributor

@marinsokol5 marinsokol5 commented Oct 18, 2024

What

  • Adding a concept of an "operation" to EditSession, the same one that we right now have in the Editor
  • When EditSession is attached to an Editor, the Editor listens to the events from EditSession and EditSession is the true owner of the event.
  • When EditSession is on it's own, it can only get programmatic changes, in which case it relies on programmatic handling of the operation lifecycle, where we still handle gracefully when that doesn't happen as expected.

Why

  • When integrating Ace in a multiple files experiences, such as IDEs or just an editor with a tab bar, you work with multiple EditSessions and you swap them out within the Editor depending on which one is currently active/focussed.
  • It's very useful for those integrators to freely do changes to EditSession, even when one is not mounted to Editor, and listen to changes through beforeEndOperation to avoid intermediary states.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Pull Request Checklist:

Copy link

One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR.

Copy link

One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR.

Copy link

One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR.

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

Attention: Patch coverage is 99.32886% with 1 line in your changes missing coverage. Please review.

Project coverage is 87.00%. Comparing base (560f5d3) to head (a44f0d1).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
src/edit_session.js 98.07% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5657      +/-   ##
==========================================
+ Coverage   86.97%   87.00%   +0.03%     
==========================================
  Files         594      594              
  Lines       43395    43516     +121     
  Branches     7170     7174       +4     
==========================================
+ Hits        37742    37862     +120     
- Misses       5653     5654       +1     
Flag Coverage Δ
unittests 87.00% <99.32%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR.

Copy link

One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR.

Copy link

One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR.

Copy link

One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR.

Copy link

One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR.

@akoreman
Copy link
Contributor

Could you add a brief description to the PR description why we want to make this change and what type of features we unblock by this?

src/editor.js Outdated
}

onStartOperation(commandEvent) {
// scrollTop is kept inside of session.curOp only for backwards compatibility reasons
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because the bottom line this.curOp = this.session.curOp = ... was inserting it.
So someone could had have integration code doing something like session.curOp.scrollTop. I fully agree though that conceptually this shouldn't be there...

Regarding backwards compatibility, are you okay with just treating this as an implementation detail on our end, since we don't really officially document it in

ace/ace.d.ts

Line 507 in 37c5f76

export interface EditSession extends EventEmitter, OptionsProvider, Folding {
or in https://ajaxorg.github.io/ace-api-docs/index.html?

@@ -347,6 +326,11 @@ class Editor {

this.$onSelectionChange = this.onSelectionChange.bind(this);
this.selection.on("changeSelection", this.$onSelectionChange);

this.$onStartOperation = this.onStartOperation.bind(this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better to do in constructor to not recreate the bound function every time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this exactly what we want, since this listener belongs to a session and should be created and cleaned up according to the session lifecycle?

Copy link

One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR.

@marinsokol5 marinsokol5 merged commit aba0575 into master Oct 21, 2024
4 checks passed
@marinsokol5 marinsokol5 deleted the edit-session-operation branch October 21, 2024 12:07
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.

4 participants