mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-65904 make editor actions not reveal information about password field contents
This commit is contained in:
+10
-3
@@ -30,6 +30,7 @@ import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.ex.util.EditorUtil;
|
||||
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -53,9 +54,16 @@ public class SelectWordAtCaretAction extends TextComponentEditorAction implement
|
||||
|
||||
@Override
|
||||
public void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) {
|
||||
SelectionModel selectionModel = editor.getSelectionModel();
|
||||
Document document = editor.getDocument();
|
||||
|
||||
if (EditorUtil.isPasswordEditor(editor)) {
|
||||
selectionModel.setSelection(0, document.getTextLength());
|
||||
return;
|
||||
}
|
||||
|
||||
int lineNumber = editor.getCaretModel().getLogicalPosition().line;
|
||||
int caretOffset = editor.getCaretModel().getOffset();
|
||||
Document document = editor.getDocument();
|
||||
if (lineNumber >= document.getLineCount()) {
|
||||
return;
|
||||
}
|
||||
@@ -72,10 +80,9 @@ public class SelectWordAtCaretAction extends TextComponentEditorAction implement
|
||||
|
||||
if (ranges.isEmpty()) return;
|
||||
|
||||
SelectionModel selectionModel = editor.getSelectionModel();
|
||||
final TextRange selectionRange = new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
|
||||
|
||||
TextRange minimumRange = new TextRange(0, editor.getDocument().getTextLength());
|
||||
TextRange minimumRange = new TextRange(0, document.getTextLength());
|
||||
for (TextRange range : ranges) {
|
||||
if (range.contains(selectionRange) && !range.equals(selectionRange)) {
|
||||
if (minimumRange.contains(range)) {
|
||||
|
||||
+18
-10
@@ -20,6 +20,7 @@ import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.VisualPosition;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
import com.intellij.openapi.editor.ex.util.EditorUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class NextPrevWordHandler extends EditorActionHandler {
|
||||
@@ -37,21 +38,28 @@ class NextPrevWordHandler extends EditorActionHandler {
|
||||
@Override
|
||||
protected void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) {
|
||||
assert caret != null;
|
||||
VisualPosition currentPosition = caret.getVisualPosition();
|
||||
if (caret.isAtBidiRunBoundary() && (myNext ^ currentPosition.leansRight)) {
|
||||
if (EditorUtil.isPasswordEditor(editor)) {
|
||||
int selectionStartOffset = caret.getLeadSelectionOffset();
|
||||
VisualPosition selectionStartPosition = caret.getLeadSelectionPosition();
|
||||
caret.moveToVisualPosition(currentPosition.leanRight(!currentPosition.leansRight));
|
||||
if (myWithSelection) {
|
||||
caret.setSelection(selectionStartPosition, selectionStartOffset, caret.getVisualPosition(), caret.getOffset());
|
||||
}
|
||||
caret.moveToOffset(myNext ? editor.getDocument().getTextLength() : 0);
|
||||
if (myWithSelection) caret.setSelection(selectionStartOffset, caret.getOffset());
|
||||
}
|
||||
else {
|
||||
if (myNext ^ caret.isAtRtlLocation()) {
|
||||
EditorActionUtil.moveCaretToNextWord(editor, myWithSelection, myInDifferentHumpsMode ^ editor.getSettings().isCamelWords());
|
||||
VisualPosition currentPosition = caret.getVisualPosition();
|
||||
if (caret.isAtBidiRunBoundary() && (myNext ^ currentPosition.leansRight)) {
|
||||
int selectionStartOffset = caret.getLeadSelectionOffset();
|
||||
VisualPosition selectionStartPosition = caret.getLeadSelectionPosition();
|
||||
caret.moveToVisualPosition(currentPosition.leanRight(!currentPosition.leansRight));
|
||||
if (myWithSelection) {
|
||||
caret.setSelection(selectionStartPosition, selectionStartOffset, caret.getVisualPosition(), caret.getOffset());
|
||||
}
|
||||
}
|
||||
else {
|
||||
EditorActionUtil.moveCaretToPreviousWord(editor, myWithSelection, myInDifferentHumpsMode ^ editor.getSettings().isCamelWords());
|
||||
if (myNext ^ caret.isAtRtlLocation()) {
|
||||
EditorActionUtil.moveCaretToNextWord(editor, myWithSelection, myInDifferentHumpsMode ^ editor.getSettings().isCamelWords());
|
||||
}
|
||||
else {
|
||||
EditorActionUtil.moveCaretToPreviousWord(editor, myWithSelection, myInDifferentHumpsMode ^ editor.getSettings().isCamelWords());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,10 @@ public final class EditorUtil {
|
||||
return editor != null && TextEditorProvider.getInstance().getTextEditor(editor) instanceof TextEditorImpl;
|
||||
}
|
||||
|
||||
public static boolean isPasswordEditor(@Nullable Editor editor) {
|
||||
return editor != null && editor.getContentComponent() instanceof JPasswordField;
|
||||
}
|
||||
|
||||
public static int getLastVisualLineColumnNumber(@NotNull Editor editor, final int line) {
|
||||
if (editor instanceof EditorImpl && ((EditorImpl)editor).myUseNewRendering) {
|
||||
LogicalPosition lineEndPosition = editor.visualToLogicalPosition(new VisualPosition(line, Integer.MAX_VALUE));
|
||||
|
||||
Reference in New Issue
Block a user