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

Already on GitHub? Sign in to your account

Remember selection/cursor and scroll position per file #2898

Merged
merged 4 commits into from Feb 20, 2013

Conversation

Projects
None yet
3 participants
Member

peterflynn commented Feb 19, 2013

This implements three related pieces of functionality:

In the process, I've added a "beforeAppClose" event and cleaned up the way DocumentManager persists info about the working set. Instead of listening to a wide variety of events (and using a guard flag to ignore cases where the events are spurious due to project switching), it now listens to "beforeAppClose".

There are two things that are a little unclean:

  • "beforeProjectClose" is fired on ProjectManager (to pair with the existing "beforeProjectClose") but triggered by DocumentCommandHandlers since that's who owns the app shutdown process. Seemed like the best option, but still not ideal...
  • EditorManager exposes two private methods for DocumentManager to get/set the remembered state related to the working set. IMHO the root issue is that EditorManager should really own the working set and its persistence, but instead DocumentManager owns it. (Especially true later if we have multiple windows, split views, etc.). Without wholesale moving all that stuff over, there's bound to be a little uncleanliness to the Editor/DocumentManager division of labor here.

peterflynn added some commits Jan 30, 2013

@peterflynn peterflynn Save & restore scroll pos & cursor/selection of working set files across
sessions, and of ALL files within a single session.

Simplify how DocumentManager saves working set state via a new
"beforeAppClose event". There's one ugly bit, a hack in EditorManager.
_restoreEditorViewState() to get around some CM API fragility.

Also save & restore scroll pos more precisely in Quick Open when user
closes it via Esc. Remove some vestiges of the very early, incomplete &
disabled code that dynamically previewed documents as you type. Plus small
cleanup in ModalBar for clarity.
ed6c2ee
@peterflynn peterflynn Merge remote-tracking branch 'origin/master' into pflynn/preserve-scr…
…oll-pos

* origin/master: (236 commits)
  Update README.md
  Update README.md
  Update README.md
  Clarified comment
  Change string literals for resizeEditor() arg to constants
  Cleaned up refresh code and made it so we always refresh after showing the editor. Addresses some cases in #2782.
  Update CodeMirror SHA. For real this time.
  Update CodeMirror SHA
  Update CodeMirror SHA to brackets-sprint20 branch, which contains a temporary cherry-pick of a fix from upstream and avoids other fixes we don't want yet.
  Update CONTRIBUTING.md
  fix exception when opening empty folder and file open
  Remove extra divider from help menu.
  Reverting to old screenshot since the styling of the new screenshot doesn't match the (reverted) background.
  Updated de to match en Getting Started CSS
  dimgray background
  Turn off newline creation when autoclosing tags
  Set text cursor.
  Update comments.
  Only skip refresh if the width hasn't changed
  prettied it up a bit
  ...

Conflicts:
	src/editor/EditorManager.js
	src/search/QuickOpen.js
dabd2e2
@peterflynn peterflynn Remove hacky workaround that is unneeded in CMv3 e785b47

@jasonsanjose jasonsanjose was assigned Feb 19, 2013

Member

jasonsanjose commented Feb 19, 2013

Reviewing

@jasonsanjose jasonsanjose and 1 other commented on an outdated diff Feb 19, 2013

src/document/DocumentCommandHandlers.js
@@ -702,7 +702,17 @@ define(function (require, exports, module) {
return CommandManager.execute(Commands.FILE_CLOSE_ALL, { promptOnly: true })
.done(function () {
_windowGoingAway = true;
+
+ // Give everyone a chance to save their state - but don't let any problems block
+ // us from quitting
+ try {
+ $(ProjectManager).trigger("beforeAppClose");
@jasonsanjose

jasonsanjose Feb 19, 2013

Member

I'm guessing this should be triggerHandler?

@peterflynn

peterflynn Feb 20, 2013

Member

Whoops, yep. I think the two behave the same in cases like this, but all our other code has clearly standardized on trigger()...

@jasonsanjose jasonsanjose and 1 other commented on an outdated diff Feb 19, 2013

src/editor/EditorManager.js
@@ -84,6 +84,13 @@ define(function (require, exports, module) {
var _lastFocusedEditor = null;
/**
+ * Maps full path to scroll pos & cursor/selection info. Not kept up to date while an editor is current.
+ * Only updated when switching / closing editor, or when requested explicitly via _getViewState().
+ * @type {Object<string, {scrollPos:{x:number, y:number}, selection:{start:{line:number, ch:number}, end:{line:number, ch:number}}}}
@jasonsanjose

jasonsanjose Feb 19, 2013

Member

Typo in @type annotation? Missing end >

@type {Object<string, {scrollPos:{x:number, y:number}, selection:{start:{line:number, ch:number}, end:{line:number, ch:number}}}>}
@peterflynn

peterflynn Feb 20, 2013

Member

Good catch -- fixed

@jasonsanjose jasonsanjose commented on the diff Feb 20, 2013

src/document/DocumentManager.js
@@ -1084,29 +1077,9 @@ define(function (require, exports, module) {
/**
* @private
- * Handle beforeProjectClose event
- */
- function _beforeProjectClose() {
- _savePreferences();
-
- // When app is shutdown via shortcut key, the command goes directly to the
- // app shell, so we can't reliably fire the beforeProjectClose event on
- // app shutdown. To compensate, we listen for currentDocumentChange,
- // workingSetAdd, and workingSetRemove events so that the prefs for
- // last project used get updated. But when switching projects, after
- // the beforeProjectChange event gets fired, DocumentManager.closeAll()
- // causes workingSetRemove event to get fired and update the prefs to an empty
- // list. So, temporarily (until projectOpen event) disallow saving prefs.
- _isProjectChanging = true;
@jasonsanjose

jasonsanjose Feb 20, 2013

Member

Just want to clarify here. Is this comment no longer valid about beforeProjectClose being unreliable?

@peterflynn

peterflynn Feb 20, 2013

Member

As best I can tell, "beforeProjectClose" is never fired on app quit -- only when switching from an old project to a new project. So in that sense it's actually quite reliable :-) I'm assuming the comment just means it's not a reliable point to save preferences... (Unless back in the day we actually did dispatch it on quit sometimes... but I couldn't find anything in the ProjectManager history to suggest that, at least).

@redmunds

redmunds Feb 20, 2013

Contributor

@peterflynn is correct that beforeProjectClose never fired on app quit.

Member

jasonsanjose commented Feb 20, 2013

Looks good. Mostly minor comments.

Member

peterflynn commented Feb 20, 2013

@jasonsanjose: changes pushed

Member

jasonsanjose commented Feb 20, 2013

Looks good. Merging.

@jasonsanjose jasonsanjose added a commit that referenced this pull request Feb 20, 2013

@jasonsanjose jasonsanjose Merge pull request #2898 from adobe/pflynn/preserve-scroll-pos
Remember selection/cursor and scroll position per file
ec8aafd

@jasonsanjose jasonsanjose merged commit ec8aafd into master Feb 20, 2013

1 check passed

default The Travis build passed
Details

@jasonsanjose jasonsanjose deleted the pflynn/preserve-scroll-pos branch Feb 20, 2013

Member

peterflynn commented Feb 20, 2013

Sweet, thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment