Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep the bold attribute when highlighting selections #434

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void Panel_draw(Panel* this, bool focus) {
}
if (item.highlightAttr) {
attrset(item.highlightAttr);
RichString_setAttr(&item, item.highlightAttr);
RichString_setAttr_preserveBold(&item, item.highlightAttr);
this->selectedLen = itemLen;
}
mvhline(y + line, x, ' ', this->w);
Expand Down
22 changes: 22 additions & 0 deletions RichString.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ inline void RichString_setAttrn(RichString* this, int attrs, int start, int fini
}
}

inline void RichString_setAttrn_preserveBold(RichString* this, int attrs, int start, int finish) {
cchar_t* ch = this->chptr + start;
finish = CLAMP(finish, 0, this->chlen - 1);
for (int i = start; i <= finish; i++) {
ch->attr = (ch->attr & A_BOLD) ? (attrs | A_BOLD) : attrs;
ch++;
}
}

int RichString_findChar(RichString* this, char c, int start) {
wchar_t wc = btowc(c);
cchar_t* ch = this->chptr + start;
Expand Down Expand Up @@ -100,6 +109,15 @@ void RichString_setAttrn(RichString* this, int attrs, int start, int finish) {
}
}

void RichString_setAttrn_preserveBold(RichString* this, int attrs, int start, int finish) {
chtype* ch = this->chptr + start;
finish = CLAMP(finish, 0, this->chlen - 1);
for (int i = start; i <= finish; i++) {
*ch = (*ch & 0xff) | attrs | (*ch & A_BOLD);
ch++;
}
}

int RichString_findChar(RichString* this, char c, int start) {
chtype* ch = this->chptr + start;
for (int i = start; i < this->chlen; i++) {
Expand All @@ -123,6 +141,10 @@ void RichString_setAttr(RichString* this, int attrs) {
RichString_setAttrn(this, attrs, 0, this->chlen - 1);
}

void RichString_setAttr_preserveBold(RichString* this, int attrs) {
RichString_setAttrn_preserveBold(this, attrs, 0, this->chlen - 1);
}

void RichString_append(RichString* this, int attrs, const char* data) {
RichString_writeFrom(this, attrs, data, this->chlen, strlen(data));
}
Expand Down
4 changes: 4 additions & 0 deletions RichString.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ typedef struct RichString_ {

void RichString_setAttrn(RichString* this, int attrs, int start, int finish);

void RichString_setAttrn_preserveBold(RichString* this, int attrs, int start, int finish);

int RichString_findChar(RichString* this, char c, int start);

void RichString_prune(RichString* this);

void RichString_setAttr(RichString* this, int attrs);

void RichString_setAttr_preserveBold(RichString* this, int attrs);

void RichString_append(RichString* this, int attrs, const char* data);

void RichString_appendn(RichString* this, int attrs, const char* data, int len);
Expand Down