fbrun: Move the cursor to the end when tab completing
+ thanks Jonas Koelker, sf.net rfe #1333003, patch #1475578
This commit is contained in:
parent
3707b74c40
commit
cb65dae95f
3 changed files with 27 additions and 10 deletions
|
@ -1,6 +1,9 @@
|
||||||
(Format: Year/Month/Day)
|
(Format: Year/Month/Day)
|
||||||
Changes for 0.9.16:
|
Changes for 0.9.16:
|
||||||
*06/04/25:
|
*06/04/25:
|
||||||
|
* fbrun: Move the cursor to the end when tab completing
|
||||||
|
(Simon + thanks Jonas Koelker), sf.net rfe #1333003, patch #1475578
|
||||||
|
util/fbrun/FbRun.hh/cc
|
||||||
* Fix up comments for doxygen (Thanks Jonas Koelker)
|
* Fix up comments for doxygen (Thanks Jonas Koelker)
|
||||||
Screen.cc CommandParser.cc Container.hh fluxbox.hh Workspace.hh
|
Screen.cc CommandParser.cc Container.hh fluxbox.hh Workspace.hh
|
||||||
ArrowButton.hh FbTk/Texture.cc FbTk/ThemeItems.cc FbTk/Texture.hh
|
ArrowButton.hh FbTk/Texture.cc FbTk/ThemeItems.cc FbTk/Texture.hh
|
||||||
|
|
|
@ -64,6 +64,7 @@ FbRun::FbRun(int x, int y, size_t width):
|
||||||
m_gc(*this),
|
m_gc(*this),
|
||||||
m_end(false),
|
m_end(false),
|
||||||
m_current_history_item(0),
|
m_current_history_item(0),
|
||||||
|
m_last_completion_prefix(""),
|
||||||
m_current_apps_item(0),
|
m_current_apps_item(0),
|
||||||
m_cursor(XCreateFontCursor(FbTk::App::instance()->display(), XC_xterm)) {
|
m_cursor(XCreateFontCursor(FbTk::App::instance()->display(), XC_xterm)) {
|
||||||
|
|
||||||
|
@ -222,10 +223,11 @@ void FbRun::redrawLabel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FbRun::keyPressEvent(XKeyEvent &ke) {
|
void FbRun::keyPressEvent(XKeyEvent &ke) {
|
||||||
|
// reset last completion prefix if we don't do a tab completion thing
|
||||||
|
bool did_tab_complete = false;
|
||||||
|
|
||||||
ke.state = FbTk::KeyUtil::instance().cleanMods(ke.state);
|
ke.state = FbTk::KeyUtil::instance().cleanMods(ke.state);
|
||||||
|
|
||||||
int cp= cursorPosition();
|
|
||||||
FbTk::TextBox::keyPressEvent(ke);
|
FbTk::TextBox::keyPressEvent(ke);
|
||||||
KeySym ks;
|
KeySym ks;
|
||||||
char keychar[1];
|
char keychar[1];
|
||||||
|
@ -238,22 +240,26 @@ void FbRun::keyPressEvent(XKeyEvent &ke) {
|
||||||
if ((ke.state & ControlMask) == ControlMask) {
|
if ((ke.state & ControlMask) == ControlMask) {
|
||||||
switch (ks) {
|
switch (ks) {
|
||||||
case XK_p:
|
case XK_p:
|
||||||
|
did_tab_complete = true;
|
||||||
prevHistoryItem();
|
prevHistoryItem();
|
||||||
break;
|
break;
|
||||||
case XK_n:
|
case XK_n:
|
||||||
|
did_tab_complete = true;
|
||||||
nextHistoryItem();
|
nextHistoryItem();
|
||||||
break;
|
break;
|
||||||
case XK_Tab:
|
case XK_Tab:
|
||||||
|
did_tab_complete = true;
|
||||||
tabCompleteHistory();
|
tabCompleteHistory();
|
||||||
setCursorPosition(cp);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if ((ke.state & (Mod1Mask|ShiftMask)) == (Mod1Mask | ShiftMask)) {
|
} else if ((ke.state & (Mod1Mask|ShiftMask)) == (Mod1Mask | ShiftMask)) {
|
||||||
switch (ks) {
|
switch (ks) {
|
||||||
case XK_less:
|
case XK_less:
|
||||||
|
did_tab_complete = true;
|
||||||
firstHistoryItem();
|
firstHistoryItem();
|
||||||
break;
|
break;
|
||||||
case XK_greater:
|
case XK_greater:
|
||||||
|
did_tab_complete = true;
|
||||||
lastHistoryItem();
|
lastHistoryItem();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -276,12 +282,14 @@ void FbRun::keyPressEvent(XKeyEvent &ke) {
|
||||||
nextHistoryItem();
|
nextHistoryItem();
|
||||||
break;
|
break;
|
||||||
case XK_Tab:
|
case XK_Tab:
|
||||||
|
did_tab_complete = true;
|
||||||
tabCompleteApps();
|
tabCompleteApps();
|
||||||
setCursorPosition(cp);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clear();
|
clear();
|
||||||
|
if (!did_tab_complete)
|
||||||
|
m_last_completion_prefix = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void FbRun::lockPosition(bool size_too) {
|
void FbRun::lockPosition(bool size_too) {
|
||||||
|
@ -347,11 +355,14 @@ void FbRun::tabCompleteHistory() {
|
||||||
} else {
|
} else {
|
||||||
unsigned int nr= 0;
|
unsigned int nr= 0;
|
||||||
unsigned int history_item = m_current_history_item - 1;
|
unsigned int history_item = m_current_history_item - 1;
|
||||||
string prefix = text().substr(0, textStartPos() + cursorPosition());
|
if (m_last_completion_prefix.empty())
|
||||||
|
m_last_completion_prefix = text().substr(0, textStartPos() + cursorPosition());
|
||||||
|
|
||||||
while (history_item != m_current_history_item && nr++ < m_history.size()) {
|
while (history_item != m_current_history_item && nr++ < m_history.size()) {
|
||||||
if (m_history[history_item].find(prefix) == 0) {
|
if (m_history[history_item].find(m_last_completion_prefix) == 0) {
|
||||||
m_current_history_item = history_item;
|
m_current_history_item = history_item;
|
||||||
setText(m_history[m_current_history_item]);
|
setText(m_history[m_current_history_item]);
|
||||||
|
cursorEnd();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (history_item == 0) // loop
|
if (history_item == 0) // loop
|
||||||
|
@ -365,15 +376,16 @@ void FbRun::tabCompleteHistory() {
|
||||||
void FbRun::tabCompleteApps() {
|
void FbRun::tabCompleteApps() {
|
||||||
|
|
||||||
static bool first_run= true;
|
static bool first_run= true;
|
||||||
static string saved_prefix= "";
|
if (m_last_completion_prefix.empty())
|
||||||
string prefix= text().substr(0, textStartPos() + cursorPosition());
|
m_last_completion_prefix = text().substr(0, textStartPos() + cursorPosition());
|
||||||
|
string prefix = m_last_completion_prefix;
|
||||||
FbTk::Directory dir;
|
FbTk::Directory dir;
|
||||||
|
|
||||||
bool add_dirs= false;
|
bool add_dirs= false;
|
||||||
bool changed_prefix= false;
|
bool changed_prefix= false;
|
||||||
|
|
||||||
// (re)build m_apps-container
|
// (re)build m_apps-container
|
||||||
if (first_run || saved_prefix != prefix) {
|
if (first_run || m_last_completion_prefix != prefix) {
|
||||||
first_run= false;
|
first_run= false;
|
||||||
|
|
||||||
string path;
|
string path;
|
||||||
|
@ -430,7 +442,7 @@ void FbRun::tabCompleteApps() {
|
||||||
sort(m_apps.begin(), m_apps.end());
|
sort(m_apps.begin(), m_apps.end());
|
||||||
unique(m_apps.begin(), m_apps.end());
|
unique(m_apps.begin(), m_apps.end());
|
||||||
|
|
||||||
saved_prefix= prefix;
|
m_last_completion_prefix = prefix;
|
||||||
changed_prefix= true;
|
changed_prefix= true;
|
||||||
m_current_apps_item= 0;
|
m_current_apps_item= 0;
|
||||||
}
|
}
|
||||||
|
@ -456,6 +468,7 @@ void FbRun::tabCompleteApps() {
|
||||||
setText(m_apps[m_current_apps_item] + "/");
|
setText(m_apps[m_current_apps_item] + "/");
|
||||||
else
|
else
|
||||||
setText(m_apps[m_current_apps_item]);
|
setText(m_apps[m_current_apps_item]);
|
||||||
|
cursorEnd();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
apps_item++;
|
apps_item++;
|
||||||
|
|
|
@ -93,6 +93,7 @@ private:
|
||||||
std::vector<std::string> m_history; ///< history list of commands
|
std::vector<std::string> m_history; ///< history list of commands
|
||||||
std::string m_history_file; ///< holds filename for command history file
|
std::string m_history_file; ///< holds filename for command history file
|
||||||
size_t m_current_history_item; ///< holds current position in command history
|
size_t m_current_history_item; ///< holds current position in command history
|
||||||
|
std::string m_last_completion_prefix; ///< last prefix we completed on
|
||||||
|
|
||||||
typedef std::vector<std::string> AppsContainer;
|
typedef std::vector<std::string> AppsContainer;
|
||||||
typedef AppsContainer::iterator AppsContainerIt;
|
typedef AppsContainer::iterator AppsContainerIt;
|
||||||
|
|
Loading…
Reference in a new issue