diff options
author | darren ha | 2013-08-02 08:55:20 +0000 |
---|---|---|
committer | Dani Megert | 2013-08-02 08:55:20 +0000 |
commit | 1726a32434ee8a113d5ab8c3441987c7aa6fdf25 (patch) | |
tree | 4e7309f2b7a14f93998fb57294d98f07d1f7dc11 /org.eclipse.ui.workbench.texteditor | |
parent | b7cf4a3570e9434b011024ad60742138c39ad6be (diff) | |
download | eclipse.platform.text-1726a32434ee8a113d5ab8c3441987c7aa6fdf25.tar.gz eclipse.platform.text-1726a32434ee8a113d5ab8c3441987c7aa6fdf25.tar.xz eclipse.platform.text-1726a32434ee8a113d5ab8c3441987c7aa6fdf25.zip |
Fixed bug 412267: [typing] Recenter command doesn't support top bottom movement just like the Emacs
Signed-off-by: darren ha <nberserk@gmail.com>
Diffstat (limited to 'org.eclipse.ui.workbench.texteditor')
-rw-r--r-- | org.eclipse.ui.workbench.texteditor/plugin.properties | 5 | ||||
-rw-r--r-- | org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/RecenterAction.java | 42 |
2 files changed, 38 insertions, 9 deletions
diff --git a/org.eclipse.ui.workbench.texteditor/plugin.properties b/org.eclipse.ui.workbench.texteditor/plugin.properties index 10cb9cf73d5..2812816bb88 100644 --- a/org.eclipse.ui.workbench.texteditor/plugin.properties +++ b/org.eclipse.ui.workbench.texteditor/plugin.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2010 IBM Corporation and others. +# Copyright (c) 2000, 2013 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ # Contributors: # IBM Corporation - initial API and implementation # Tom Eicher (Avaloq Evolution AG) - block selection mode +# Daesung Ha <nberserk@gmail.com> - update recenter command description ############################################################################### pluginName= Text Editor Framework providerName= Eclipse.org @@ -167,7 +168,7 @@ command.windowEnd.description = Go to the end of the window command.windowEnd.name = Window End command.windowStart.description = Go to the start of the window command.windowStart.name = Window Start -command.recenter.description = Recenter the window based on the cursor +command.recenter.description = Scroll cursor line to center, top and bottom command.recenter.name = Recenter command.joinLines.description = Join lines of text command.joinLines.name = Join Lines diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/RecenterAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/RecenterAction.java index 61964eebe67..3bfd31a43c0 100644 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/RecenterAction.java +++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/RecenterAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. + * Copyright (c) 2006, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Daesung Ha <nberserk@gmail.com> - supports top and bottom scrolling - https://bugs.eclipse.org/bugs/show_bug.cgi?id=412267 *******************************************************************************/ package org.eclipse.ui.texteditor; @@ -18,11 +19,17 @@ import org.eclipse.jface.text.source.ISourceViewer; /** * An action to handle emacs-like recenter. - * This function scrolls the selected window to put the cursor at the middle of the screen. + * This function scrolls the selected window to put the cursor at the middle/top/bottom of the screen. * * @since 3.3 */ public class RecenterAction extends TextEditorAction { + private static final int RECENTER_MIDDLE= 0; + private static final int RECENTER_TOP= 1; + private static final int RECENTER_BOTTOM= 2; + private static final int RECENTER_POS_SIZE= 3; + private int fPrevOffset= -1; + private int fDestPos; /** * Creates a new action for the given text editor. The action configures its @@ -57,11 +64,32 @@ public class RecenterAction extends TextEditorAction { // compute the number of lines displayed int height= st.getClientArea().height; int lineHeight= st.getLineHeight(); + int rowPerScreen= height / lineHeight; int caretOffset= st.getCaretOffset(); - int caretLine= st.getLineAtOffset(caretOffset); - - int topLine= Math.max(0, (caretLine - (height / (lineHeight * 2)))); - st.setTopIndex(topLine); + int caretLine= st.getLineAtOffset(caretOffset); + if (caretOffset==fPrevOffset) { // if successive call in same position + fDestPos++; + fDestPos%= RECENTER_POS_SIZE; + }else{ + fDestPos= RECENTER_MIDDLE; + } + fPrevOffset= caretOffset; + + int line= 0; + switch (fDestPos) { + case RECENTER_MIDDLE: + line= Math.max(0, (caretLine - rowPerScreen / 2)); + break; + case RECENTER_TOP: + line= caretLine; + break; + case RECENTER_BOTTOM: + line= Math.max(0, caretLine - rowPerScreen + 1); + break; + default: + break; + } + st.setTopIndex(line); } -} +}
\ No newline at end of file |