Merge pull request #379 from WookeyBiscotti/caret_navigation_commands

Add caret navigation
This commit is contained in:
Vadim Lopatin 2018-06-13 16:50:57 +03:00 committed by GitHub
commit da20313a1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 86 additions and 2 deletions

View File

@ -117,6 +117,7 @@ class DEditorTool : EditorTool
auto destPos = byteOffsetToCaret(content, target);
_frame.currentEditor.setCaretPos(destPos.line,destPos.pos, true, true);
_frame.currentEditor.setFocus();
_frame.caretHistory.pushNewPosition();
break;
default:
break;

View File

@ -72,6 +72,8 @@ enum IDEActions : int {
GetDocComments,
GetParenCompletion,
GotoLine,
GotoNextPosition,
GotoPrevPosition,
InsertCompletion,
FindInFiles,
@ -176,7 +178,9 @@ const Action ACTION_GET_DOC_COMMENTS = (new Action(IDEActions.GetDocComments, "
const Action ACTION_GO_TO_DEFINITION = (new Action(IDEActions.GoToDefinition, "GO_TO_DEFINITION"c, ""c, KeyCode.KEY_G, KeyFlag.Control)).addAccelerator(KeyCode.F12, 0).disableByDefault();
const Action ACTION_GET_COMPLETIONS = (new Action(IDEActions.GetCompletionSuggestions, "SHOW_COMPLETIONS"c, ""c, KeyCode.KEY_G, KeyFlag.Control|KeyFlag.Shift)).addAccelerator(KeyCode.SPACE, KeyFlag.Control).disableByDefault();
const Action ACTION_GET_PAREN_COMPLETION = (new Action(IDEActions.GetParenCompletion, "SHOW_PAREN_COMPLETION"c, ""c, KeyCode.SPACE, KeyFlag.Control|KeyFlag.Shift)).disableByDefault();
const Action ACTION_GO_TO_LINE = (new Action(IDEActions.GotoLine, "GO_TO_LINE"c, ""c, KeyCode.KEY_L, KeyFlag.Control|KeyFlag.Option)).disableByDefault();;
const Action ACTION_GO_TO_LINE = (new Action(IDEActions.GotoLine, "GO_TO_LINE"c, ""c, KeyCode.KEY_L, KeyFlag.Control|KeyFlag.Option)).disableByDefault();
const Action ACTION_GO_TO_PREV_POSITION = (new Action(IDEActions.GotoPrevPosition, "GO_TO_PREV_POSITION"c, ""c, KeyCode.LEFT, KeyFlag.Alt)).disableByDefault();
const Action ACTION_GO_TO_NEXT_POSITION = (new Action(IDEActions.GotoNextPosition, "GO_TO_NEXT_POSITION"c, ""c, KeyCode.RIGHT, KeyFlag.Alt)).disableByDefault();
const Action ACTION_FIND_TEXT = (new Action(IDEActions.FindInFiles, "FIND_IN_FILES"c, "edit-find"c, KeyCode.KEY_F, KeyFlag.Control | KeyFlag.Shift)).disableByDefault();
const Action ACTION_TOOLS_OPEN_DMD_TRACE_LOG = (new Action(IDEActions.ToolsOpenDMDTraceLog, "OPEN_DMD_TRACE_LOG"c));
@ -204,5 +208,7 @@ const Action[] STD_IDE_ACTIONS = [
ACTION_GET_COMPLETIONS,
ACTION_GET_PAREN_COMPLETION,
ACTION_GO_TO_LINE,
ACTION_GO_TO_PREV_POSITION,
ACTION_GO_TO_NEXT_POSITION,
ACTION_FIND_TEXT,
];

View File

@ -108,6 +108,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
window.onCanClose = &onCanClose;
window.onClose = &onWindowClose;
applySettings(_settings);
caretHistory = new CaretHistory;
}
~this() {
@ -401,8 +402,10 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
Log.d("found source file");
if (sourceFile)
_wsPanel.selectItem(sourceFile);
caretHistory.pushNewPosition();
currentEditor().setCaretPos(line, 0);
currentEditor().setCaretPos(line, column);
caretHistory.pushNewPosition();
}
return true;
}
@ -770,7 +773,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
MenuItem navItem = new MenuItem(new Action(21, "MENU_NAVIGATE"));
navItem.add(ACTION_GO_TO_DEFINITION, ACTION_GET_COMPLETIONS, ACTION_GET_DOC_COMMENTS,
ACTION_GET_PAREN_COMPLETION, ACTION_EDITOR_GOTO_PREVIOUS_BOOKMARK,
ACTION_EDITOR_GOTO_NEXT_BOOKMARK, ACTION_GO_TO_LINE);
ACTION_EDITOR_GOTO_NEXT_BOOKMARK, ACTION_GO_TO_LINE, ACTION_GO_TO_PREV_POSITION, ACTION_GO_TO_NEXT_POSITION);
MenuItem projectItem = new MenuItem(new Action(21, "MENU_PROJECT"));
projectItem.add(ACTION_PROJECT_SET_STARTUP, ACTION_PROJECT_REFRESH, ACTION_PROJECT_UPDATE_DEPENDENCIES, ACTION_PROJECT_SETTINGS);
@ -988,6 +991,8 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
case IDEActions.FileSaveAll:
case IDEActions.FileSaveAs:
case IDEActions.GotoLine:
case IDEActions.GotoPrevPosition:
case IDEActions.GotoNextPosition:
case EditorActions.Find:
case EditorActions.FindNext:
case EditorActions.FindPrev:
@ -1284,6 +1289,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
case IDEActions.GoToDefinition:
if (currentEditor) {
Log.d("Trying to go to definition.");
caretHistory.pushNewPosition();
currentEditor.editorTool.goToDefinition(currentEditor(), currentEditor.caretPos);
}
return true;
@ -1302,8 +1308,10 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
return;
}
// Go to line
caretHistory.pushNewPosition();
currentEditor.setCaretPos(num - 1, 0);
currentEditor.setFocus();
caretHistory.pushNewPosition();
}
catch (ConvException e) {
currentEditor.setFocus();
@ -1312,6 +1320,18 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
});
}
return true;
case IDEActions.GotoPrevPosition:
if (currentEditor) {
Log.d("Go to prev position");
caretHistory.moveToPrev();
}
return true;
case IDEActions.GotoNextPosition:
if (currentEditor) {
Log.d("Go to next position");
caretHistory.moveToNext();
}
return true;
case IDEActions.GetDocComments:
Log.d("Trying to get doc comments.");
currentEditor.editorTool.getDocComments(currentEditor, currentEditor.caretPos, delegate(string[] results) {
@ -2029,5 +2049,58 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
Log.i("onWindowClose()");
stopExecution();
}
static struct CaretPosition {
string filePath;
uint line;
uint pos;
};
class CaretHistory {
private CaretPosition[] caretHistory;
private int currentPos = -1;
private bool checkIfCurentPosIsCurrentHistoryPos() {
if (caretHistory.length == 0) {
return false;
}
return currentEditor.caretPos.line == caretHistory[currentPos].line &&
currentEditor.caretPos.pos == caretHistory[currentPos].pos;
}
void pushNewPosition() {
if (!checkIfCurentPosIsCurrentHistoryPos()) {
pushNewPosition(currentEditor().filename, currentEditor.caretPos.line, currentEditor.caretPos.pos);
}
}
void pushNewPosition(string filePath, uint line, uint pos) {
if (caretHistory.length != 0) {
caretHistory = caretHistory[0..currentPos + 1];
}
caretHistory ~= CaretPosition(filePath, line, pos);
++currentPos;
}
void moveToNext() {
if (currentPos + 1 < caretHistory.length) {
++currentPos;
openSourceFile(caretHistory[currentPos].filePath);
currentEditor.setCaretPos(caretHistory[currentPos].line, caretHistory[currentPos].pos);
currentEditor.setFocus();
}
}
void moveToPrev() {
if (currentPos > 0) {
--currentPos;
openSourceFile(caretHistory[currentPos].filePath);
currentEditor.setCaretPos(caretHistory[currentPos].line, caretHistory[currentPos].pos);
currentEditor.setFocus();
}
}
}
CaretHistory caretHistory;
}

View File

@ -352,9 +352,11 @@ class SearchWidget : TabWidget {
line--;
if (line == 0) {
if (_frame.openSourceFile(matchList.filename)) {
_frame.caretHistory.pushNewPosition();
_frame.currentEditor.setCaretPos(match.line, to!int(match.col));
_frame.currentEditor.setTextToHighlight(_findText.text, makeSearchFlags);
_frame.currentEditor.setFocus();
_frame.caretHistory.pushNewPosition();
}
return true;
}

View File

@ -78,6 +78,8 @@ SHOW_COMPLETIONS=Get autocompletions
SHOW_DOC_COMMENTS=Show documentation
SHOW_PAREN_COMPLETION=Call hints
GO_TO_LINE=Go to line
GO_TO_PREV_POSITION=Go to previous position
GO_TO_NEXT_POSITION=Go to next position
FIND_IN_FILES=Find in files...