Skip to content

Commit

Permalink
Selection send and recv should use independent partial-state storage
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed Sep 6, 2021
1 parent dbf8c6a commit 24e6efc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
30 changes: 15 additions & 15 deletions src/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ static void osc_selection(VTermState *state, VTermStringFragment frag)
}
else {
state->tmp.selection.state = SELECTION_SET_INITIAL;
state->tmp.selection.partial = 0;
state->tmp.selection.recvpartial = 0;
}
}

Expand All @@ -1633,11 +1633,11 @@ static void osc_selection(VTermState *state, VTermStringFragment frag)
uint32_t x = 0; /* Current decoding value */
int n = 0; /* Number of sextets consumed */

if(state->tmp.selection.partial) {
n = state->tmp.selection.partial >> 24;
x = state->tmp.selection.partial & 0x03FFFF; /* could be up to 18 bits of state in here */
if(state->tmp.selection.recvpartial) {
n = state->tmp.selection.recvpartial >> 24;
x = state->tmp.selection.recvpartial & 0x03FFFF; /* could be up to 18 bits of state in here */

state->tmp.selection.partial = 0;
state->tmp.selection.recvpartial = 0;
}

while((state->selection.buflen - bufcur) >= 3 && frag.len) {
Expand Down Expand Up @@ -1696,7 +1696,7 @@ static void osc_selection(VTermState *state, VTermStringFragment frag)
}

if(n)
state->tmp.selection.partial = (n << 24) | x;
state->tmp.selection.recvpartial = (n << 24) | x;
}
}

Expand Down Expand Up @@ -2197,7 +2197,7 @@ void vterm_state_send_selection(VTermState *state, VTermSelectionMask mask, VTer

vterm_push_output_sprintf_str(vt, C1_OSC, false, "52;%c;", selection_chars[idx]);

state->tmp.selection.partial = 0;
state->tmp.selection.sendpartial = 0;
}

if(frag.len) {
Expand All @@ -2207,11 +2207,11 @@ void vterm_state_send_selection(VTermState *state, VTermSelectionMask mask, VTer
uint32_t x = 0;
int n = 0;

if(state->tmp.selection.partial) {
n = state->tmp.selection.partial >> 24;
x = state->tmp.selection.partial & 0xFFFFFF;
if(state->tmp.selection.sendpartial) {
n = state->tmp.selection.sendpartial >> 24;
x = state->tmp.selection.sendpartial & 0xFFFFFF;

state->tmp.selection.partial = 0;
state->tmp.selection.sendpartial = 0;
}

while((state->selection.buflen - bufcur) >= 4 && frag.len) {
Expand Down Expand Up @@ -2240,13 +2240,13 @@ void vterm_state_send_selection(VTermState *state, VTermSelectionMask mask, VTer
}

if(n)
state->tmp.selection.partial = (n << 24) | x;
state->tmp.selection.sendpartial = (n << 24) | x;
}

if(frag.final) {
if(state->tmp.selection.partial) {
int n = state->tmp.selection.partial >> 24;
uint32_t x = state->tmp.selection.partial & 0xFFFFFF;
if(state->tmp.selection.sendpartial) {
int n = state->tmp.selection.sendpartial >> 24;
uint32_t x = state->tmp.selection.sendpartial & 0xFFFFFF;
char *buffer = state->selection.buffer;

/* n is either 1 or 2 now */
Expand Down
3 changes: 2 additions & 1 deletion src/vterm_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ struct VTermState
SELECTION_SET_INITIAL,
SELECTION_SET,
} state : 8;
uint32_t partial;
uint32_t recvpartial;
uint32_t sendpartial;
} selection;
} tmp;

Expand Down

0 comments on commit 24e6efc

Please sign in to comment.