Skip to content

Commit

Permalink
Fix #1369
Browse files Browse the repository at this point in the history
  • Loading branch information
gnunn1 committed Apr 14, 2018
1 parent 35f9a08 commit 259f29d
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 1 deletion.
9 changes: 9 additions & 0 deletions data/gsettings/com.gexperts.Tilix.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,15 @@
<default>'disabled'</default>
<summary>Keyboard shortcut to open directory in file browser</summary>
</key>
<!-- Move between prompts -->
<key name="terminal-next-prompt" type="s">
<default>'disabled'</default>
<summary>Keyboard shortcut to move to next prompt</summary>
</key>
<key name="terminal-previous-prompt" type="s">
<default>'disabled'</default>
<summary>Keyboard shortcut to move to previous prompt</summary>
</key>
<!-- Nautilus Shortcut for Open in Tilix -->
<key name="nautilus-open" type="s">
<default>'&lt;Ctrl&gt;&lt;Alt&gt;t'</default>
Expand Down
12 changes: 12 additions & 0 deletions data/resources/ui/shortcuts.ui
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,18 @@
<property name="title" translatable="yes" context="shortcut window">Page down</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut" id ="terminal-previous-prompt">
<property name="visible">1</property>
<property name="title" translatable="yes" context="shortcut window">Previous prompt</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut" id ="terminal-next-prompt">
<property name="visible">1</property>
<property name="title" translatable="yes" context="shortcut window">Next prompt</property>
</object>
</child>
</object>
</child>
<child>
Expand Down
11 changes: 11 additions & 0 deletions source/gx/tilix/prefeditor/prefdialog.d
Original file line number Diff line number Diff line change
Expand Up @@ -976,10 +976,18 @@ private:
return result;
}

TerminalFeature[string] getVTEFeatureShortcuts() {
TerminalFeature[string] result;
result["terminal-next-prompt"] = TerminalFeature.EVENT_SCREEN_CHANGED;
result["terminal-previous-prompt"] = TerminalFeature.EVENT_SCREEN_CHANGED;
return result;
}

void loadShortcuts(TreeStore ts) {

int[2][string] gtkVersioned = getGTKVersionedShortcuts();
int[2][string] vteVersioned = getVTEVersionedShortcuts();
TerminalFeature[string] vteFeatured = getVTEFeatureShortcuts();

loadLocalizedShortcutLabels();
string[] keys = gsShortcuts.listKeys();
Expand All @@ -997,6 +1005,9 @@ private:
int[2] vteVersion = vteVersioned[key];
if (!checkVTEVersionNumber(vteVersion[0], vteVersion[1])) continue;
}
if (key in vteFeatured) {
if (!checkVTEFeature(vteFeatured[key])) continue;
}

string prefix, id;
getActionNameFromKey(key, prefix, id);
Expand Down
4 changes: 3 additions & 1 deletion source/gx/tilix/terminal/actions.d
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ enum ACTION_SCROLL_DOWN = "scroll-down";
enum ACTION_PAGE_UP = "page-up";
enum ACTION_PAGE_DOWN = "page-down";
enum ACTION_MONITOR_SILENCE = "monitor-silence";
enum ACTION_FILE_BROWSER = "file-browser";
enum ACTION_FILE_BROWSER = "file-browser";
enum ACTION_PREVIOUS_PROMPT = "previous-prompt";
enum ACTION_NEXT_PROMPT = "next-prompt";
65 changes: 65 additions & 0 deletions source/gx/tilix/terminal/terminal.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import std.format;
import std.json;
import std.math;
import std.process;
import std.range;
import std.regex;
import std.stdio;
import std.string;
Expand Down Expand Up @@ -567,6 +568,16 @@ private:
}
});

if (checkVTEFeature(TerminalFeature.EVENT_SCREEN_CHANGED)) {
registerActionWithSettings(group, ACTION_PREFIX, ACTION_NEXT_PROMPT, gsShortcuts, delegate(GVariant, SimpleAction) {
moveToPrompt(1);
});
registerActionWithSettings(group, ACTION_PREFIX, ACTION_PREVIOUS_PROMPT, gsShortcuts, delegate(GVariant, SimpleAction) {
moveToPrompt(-1);
});
}


registerActionWithSettings(group, ACTION_PREFIX, ACTION_SELECT_ALL, gsShortcuts, delegate(GVariant, SimpleAction) { vte.selectAll(); });

//Link Actions, no shortcuts, context menu only
Expand Down Expand Up @@ -667,6 +678,8 @@ private:
});
registerActionWithSettings(group, ACTION_PREFIX, ACTION_RESET_AND_CLEAR, gsShortcuts, delegate(GVariant, SimpleAction) {
vte.reset(true, true);
// Clear history of prompts
checkPromptBuffer();
if (isSynchronizedInput()) {
SyncInputEvent se = SyncInputEvent(_terminalUUID, SyncInputEventType.RESET_AND_CLEAR, null, null);
onSyncInput.emit(this, se);
Expand Down Expand Up @@ -1028,6 +1041,13 @@ private:
vteHandlers ~= vte.addOnKeyPress(delegate(Event event, Widget widget) {
if (vte is null) return false;

if (event.key.keyval == GdkKeysyms.GDK_Return && checkVTEFeature(TerminalFeature.EVENT_SCREEN_CHANGED) && currentScreen == TerminalScreen.NORMAL) {
long row, column;
vte.getCursorPosition(column, row);
promptPosition ~= [row];
tracef("Added prompt position %d", row);
}

if (isSynchronizedInput() && event.key.sendEvent != SendEvent.SYNC) {
static if (USE_COMMIT_SYNCHRONIZATION) {
// Only synchronize hard code VTE keys otherwise let commit event take care of it
Expand Down Expand Up @@ -1060,6 +1080,15 @@ private:
});
}

// Used to track changes to scroll buffer to clear
// prompt positions if user cleared VTE buffer, i.e. "clear" command.
// Used for terminal-next-prompt and terminal-previous-prompt actions
if (checkVTEFeature(TerminalFeature.EVENT_SCREEN_CHANGED)) {
vte.addOnTextDeleted(delegate(VTE) {
checkPromptBuffer();
});
}

pmContext = new Popover(vte);
pmContext.setModal(true);
pmContext.setPosition(PositionType.BOTTOM);
Expand Down Expand Up @@ -1476,6 +1505,41 @@ private:
onSessionAttach.emit(this, sessionUUID);
}

// Block for handling cycling between command prompts
private:
long[] promptPosition;

void moveToPrompt(int direction) {
if (!checkVTEFeature(TerminalFeature.EVENT_SCREEN_CHANGED) || currentScreen != TerminalScreen.NORMAL) return;
long result;
long row = to!long(vte.getVadjustment().getValue());
auto sorted = assumeSorted(promptPosition);
if (direction < 0) {
auto range = sorted.lowerBound(row);
if (range.length > 0) {
result = range[range.length -1];
} else result = 0;
} else {
auto range = sorted.upperBound(row);
if (range.length > 0) {
result = range[0];
} else result = to!long(vte.getVadjustment().getUpper());
}
tracef("Current row %d, Moving to command prompt at %d", row, result);
vte.getVadjustment.setValue(to!double(result));
}

void checkPromptBuffer() {
if (!checkVTEFeature(TerminalFeature.EVENT_SCREEN_CHANGED) || currentScreen != TerminalScreen.NORMAL) return;
if (promptPosition.length == 0) return;
// If upper bound of last recorded prompt is bigger then current upper bound of rows user must have cleared buffer, i.e. clear command
tracef("Check position %d against buffer size %f", promptPosition[promptPosition.length -1], vte.getVadjustment().getUpper());
if (promptPosition[promptPosition.length -1] < vte.getVadjustment().getUpper()) {
promptPosition = [];
trace("Cleared prompt positions");
}
}

// Block for processing triggers
private:

Expand Down Expand Up @@ -3689,6 +3753,7 @@ public:
break;
case SyncInputEventType.RESET_AND_CLEAR:
vte.reset(true, true);
checkPromptBuffer();
break;
}
}
Expand Down

0 comments on commit 259f29d

Please sign in to comment.