~damien/jedit-lsp

10e97595d8de1fca3c009517d24acca37eb4bca3 — Eric Le Lay 2 months ago e3dbf1a
fix key handling in edit install script dialog
1 files changed, 25 insertions(+), 45 deletions(-)

M lsp/options/ScriptDialog.java
M lsp/options/ScriptDialog.java => lsp/options/ScriptDialog.java +25 -45
@@ 1,7 1,5 @@
package lsp.options;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.BorderLayout;
import javax.swing.Box;
import javax.swing.BoxLayout;


@@ 9,11 7,16 @@ import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import org.gjt.sp.jedit.IPropertyManager;
import org.gjt.sp.jedit.JEditActionSet;
import org.gjt.sp.jedit.JEditBeanShellAction;
import org.gjt.sp.jedit.View;
import org.gjt.sp.jedit.gui.EnhancedDialog;
import org.gjt.sp.jedit.jEdit;
import org.gjt.sp.jedit.textarea.JEditEmbeddedTextArea;
import org.gjt.sp.util.Log;
import org.gjt.sp.jedit.textarea.StandaloneTextArea;
import org.gjt.sp.jedit.textarea.TextArea;
import org.jedit.keymap.Keymap;

public class ScriptDialog extends EnhancedDialog {
	private final JEditEmbeddedTextArea textArea;


@@ 30,7 33,25 @@ public class ScriptDialog extends EnhancedDialog {
		this.textArea = new JEditEmbeddedTextArea();
		this.textArea.getBuffer().setMode("beanshell");
		this.textArea.setText(text != null && !text.isEmpty() ? text : "// BeanShell script here");
		this.textArea.addKeyListener(new InputHandler());
		// See ActionSet class: it uses KeyMap.getShortcut() instead of getProperty() to get the shortcut associated with an action
		// and most users set a property prev-char.shortcut but use the keymap instead (or use the default)
		JEditActionSet<JEditBeanShellAction> actionSet = new StandaloneTextArea.StandaloneActionSet(
				new IPropertyManager() {
					private Keymap km = jEdit.getKeymapManager().getKeymap();
					@Override
					public String getProperty(String name) {
						String value = jEdit.getPropertyManager().getProperty(name);
						if (value != null) {
							return value;
						}
						return km.getShortcut(name);
					}
				},
				textArea,
				TextArea.class.getResource("textarea.actions.xml"));
		textArea.addActionSet(actionSet);
		actionSet.load();
		actionSet.initKeyBindings();
		content.add(BorderLayout.CENTER, textArea);

		Box buttons = new Box(BoxLayout.X_AXIS);


@@ 67,45 88,4 @@ public class ScriptDialog extends EnhancedDialog {
	public String getText() {
		return this.textArea.getText();
	}

	private class InputHandler extends KeyAdapter {
		@Override
		public void keyPressed(KeyEvent e) {
			// Not sure why this is necessary, but otherwise some actions within the text area have no effect
			switch (e.getKeyCode()) {
				case KeyEvent.VK_ENTER:
					e.consume();
					break;

				case KeyEvent.VK_BACK_SPACE:
					e.consume();
					if (e.isControlDown()) {
						textArea.backspaceWord();
					} else {
						textArea.backspace();
					}
					break;

				case KeyEvent.VK_LEFT:
					e.consume();
					textArea.goToPrevCharacter(e.isShiftDown());
					break;

				case KeyEvent.VK_RIGHT:
					e.consume();
					textArea.goToNextCharacter(e.isShiftDown());
					break;

				case KeyEvent.VK_UP:
					e.consume();
					textArea.goToPrevLine(e.isShiftDown());
					break;

				case KeyEvent.VK_DOWN:
					e.consume();
					textArea.goToNextLine(e.isShiftDown());
					break;
			}
		}
	}
}