Skip to content

Commit

Permalink
Keep the text marking to visualize the final match
Browse files Browse the repository at this point in the history
And some related refactoring, less nesting and pointless value passing.
Also not interpreting directories as final match.

Addressing part of #297, a proposal displaying solution is yet to come.
  • Loading branch information
Code7R committed Sep 30, 2018
1 parent 25538d4 commit 5243d44
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
20 changes: 7 additions & 13 deletions src/aaddressbar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ bool AddressBar::handleKey(const XKeyEvent &key) {
else if (k == XK_Up ||
(k == XK_KP_Up && !(key.state & xapp->NumLockMask)))
{
return changeLocation(location - 1);
return changeLocation(location - 1), true;
}
else if (k == XK_Down ||
(k == XK_KP_Down && !(key.state & xapp->NumLockMask)))
{
return changeLocation(location + 1);
return changeLocation(location + 1), true;
}
}
return YInputLine::handleKey(key);
Expand Down Expand Up @@ -80,17 +80,11 @@ bool AddressBar::handleReturn(int mask) {
return true;
}

bool AddressBar::changeLocation(int newLocation) {
if (inrange(newLocation, 0, history.getCount())) {
location = newLocation;
if (location == history.getCount()) {
setText(null);
}
else {
setText(history[location]);
}
}
return true;
void AddressBar::changeLocation(int newLocation) {
if (! inrange(newLocation, 0, history.getCount()))
return;
location = newLocation;
setText(location == history.getCount() ? null : history[location], true);
}

void AddressBar::showNow() {
Expand Down
2 changes: 1 addition & 1 deletion src/aaddressbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AddressBar: public YInputLine {
void hideNow();

private:
bool changeLocation(int newLocation);
void changeLocation(int newLocation);
bool handleReturn(int mask);

IApp *app;
Expand Down
14 changes: 8 additions & 6 deletions src/yinput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ YInputLine::YInputLine(YWindow *parent):
YInputLine::~YInputLine() {
}

void YInputLine::setText(const ustring &text) {
void YInputLine::setText(const ustring &text, bool asMarked) {
fText = text;
leftOfs = 0;
curPos = fText.length();
markPos = curPos;
markPos = asMarked ? 0 : curPos;
limit();
repaint();
}
Expand Down Expand Up @@ -680,10 +680,12 @@ void YInputLine::autoScroll(int delta, const XMotionEvent *motion) {

void YInputLine::complete() {
char* res = 0;
if (1 <= globit_best(cstring(fText), &res, 0, 0))
setText(res);
// FIXME: even for max. prefix the text gets marked like for a full match;
// that might be intended or might be a bug in limit() or paint()
int res_count = globit_best(cstring(fText), &res, 0, 0);
// directory is not a final match
if(res_count == 1 && upath(res).dirExists())
res_count++;

This comment has been minimized.

Copy link
@Code7R

Code7R Sep 30, 2018

Author Collaborator

@gijsbers I know this is not perfect but is IMO sufficient as stopgap solution. And I still intend to migrate globit.c to globit.cc and make it more C++ like (i.e. make use of dtors). globit.c does not handle file modes and it does not indicate what it matched (file? directory?) and fixing this is feasible but the code would become too ugly for my taste.

If you disagree or cannot wait for it, please discuss in #297 or assign it to yourself. Thanks.

This comment has been minimized.

Copy link
@gijsbers

gijsbers Sep 30, 2018

Collaborator

Okay, great!

if (1 <= res_count)
setText(res, res_count == 1);
free(res);
}

Expand Down
2 changes: 1 addition & 1 deletion src/yinputline.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class YInputLine: public YWindow, public YTimerListener, public YActionListener
YInputLine(YWindow *parent = 0);
virtual ~YInputLine();

void setText(const ustring &text);
void setText(const ustring &text, bool asMarked);
ustring getText();

virtual void paint(Graphics &g, const YRect &r);
Expand Down

0 comments on commit 5243d44

Please sign in to comment.