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

Editor Scroll #681

Merged
merged 7 commits into from
Sep 15, 2016
Merged

Editor Scroll #681

merged 7 commits into from
Sep 15, 2016

Conversation

rebornix
Copy link
Member

Add editor scroll commands. The trick in this PR is disabling view updating for editor scrolling as Code already does it for us, re-updating the view will lead to unexpected result of layout redraw.

This PR should fix #672, #673, #675, #676 .

@rebornix
Copy link
Member Author

Fix #677 as well. After reading @sandeep 's source code now I understand lineNumber parameter correctly.

@@ -1466,6 +1510,28 @@ class CommandCenterScroll extends BaseCommand {
}

@RegisterAction
class COmmandTopScroll extends BaseCommand {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor casing issue - there's an uppercase O in CommandTopScroll

Copy link
Member Author

Choose a reason for hiding this comment

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

Ooops, I've put too much time on shift ...

@johnfn
Copy link
Member

johnfn commented Aug 31, 2016

I've mentioned before that I dislike updating the view outside of our updateView function, though in the past I never really drew a hard line. However, I've actually started to take steps to minimize this behavior within my multi-cursor-mode branch, and I think it would be prudent to begin to draw the line and say we want to do that everywhere. (This has a zillion benefits, least of which include separation of concerns, really simplifying macros and speeding up . down the line.)

The way I'd suggest to do something like this would be that for actions that can adjust the view, make simple interfaces like { type: 'scrollViewToTop' } { type: 'scrollViewToBottom' } etc. Then make a property on VimState which is something like viewChanges. Then read off this array inside of the updateView function.

@rebornix
Copy link
Member Author

rebornix commented Sep 2, 2016

@johnfn ha I was expecting this feedback on this :)

I do agree that any side effect should happen in a centralized place like updateView but sometimes it's difficult. The reason that Code won't provide a pure command for us to call (I mentioned quite a bit times) is a pure command without any side effect may be not useful to other callers and way too Vim specific.

The top 1st command/API that conflicts with your principle (making commands pure/ putting view updating all in viewUpdate) is vscode.window.activeTextEditor.edit(). We leveraged this API to archive delete and replace but they will update the view immediately once they are executed. This makes it difficult to draw the hard line.

I'm not against your proposal and actually I do want to make it this way in VSCodeVim but we do have limitations. I'll read your multi-cursor PR to grab ideas from you and update this PR accordingly.

@johnfn
Copy link
Member

johnfn commented Sep 3, 2016

For the pure, just scroll and do nothing else commands, I think it's possible! But the other ones will be more difficult, you're right. Kind of a bummer.

@jpoon
Copy link
Member

jpoon commented Sep 7, 2016

This would also fix #210

@rebornix
Copy link
Member Author

@johnfn @jpoon just followed Johnfn's suggestions, postpone Code commands which have side effect to view layout and only run them when we trigger our inhouse updateView, making it a little bit similar to https://github.com/VSCodeVim/Vim/pull/587/files#diff-a7723f32fe6b05e135838f84e5c23c0fR371 .

Look forward to your comments on this.

Copy link
Member

@jpoon jpoon left a comment

Choose a reason for hiding this comment

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

Noice!

@@ -609,16 +635,49 @@ class CommandDeleteIndentInCurrentLine extends BaseCommand {
}
}

class CommandCtrlE extends CommandEditorScroll {
keys = ["<C-e>"];
to = "down";
Copy link
Member

Choose a reason for hiding this comment

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

Can we create enums for to and by values?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, that's definitely necessary.

@@ -1088,6 +1100,15 @@ export class ModeHandler implements vscode.Disposable {

vscode.window.activeTextEditor.setDecorations(this._caretDecoration, rangesToDraw);

if (this.vimState.postponedCodeViewChanges.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

is this outside if necessary?

@@ -33,6 +33,11 @@ export enum VimSpecialCommands {
Dot
}

export class ViewChange {
public name: string;
Copy link
Member

@jpoon jpoon Sep 14, 2016

Choose a reason for hiding this comment

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

nit: maybe rename this to command? As that'll be inline with how it's used in executeCommand.

@rebornix
Copy link
Member Author

@jpoon comments addressed!

Copy link
Member

@johnfn johnfn left a comment

Choose a reason for hiding this comment

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

Thank you for pulling out the view-changing actions! :)

Fix the string things and lets do this!

/**
* Positions in the view for cursor move command.
*/
export const CursorMovePosition = {
Copy link
Member

Choose a reason for hiding this comment

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

You could actually just use string union types here, which I like better (stronger typechecking).

type CursorMovePosition = 'left' | 'right' | 'up' | 'down' | ...

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, string union type can easily validate string value assignment but if we use that, then we still need to write plain text string while initialization in action.ts, which is what we want to avoid, right?

@rebornix rebornix merged commit cf1036b into VSCodeVim:master Sep 15, 2016
This pull request was closed.
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.

Ctrl-E and Ctrl-I stop working as soon as the cursor should move
4 participants