MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / acceptSearch

Function acceptSearch

tools/shell/linenoise.cpp:2755–2795  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2753}
2754
2755static char acceptSearch(linenoiseState* l, char nextCommand) {
2756 bool hasMatches = false;
2757 int history_index = l->prev_search_match_history_index;
2758 if (l->search_index < l->search_matches.size()) {
2759 // if there is a match - copy it into the buffer
2760 auto match = l->search_matches[l->search_index];
2761 hasMatches = true;
2762 history_index = match.history_index;
2763 }
2764
2765 while (history_len > 1 && history_index != (history_len - 1 - l->history_index)) {
2766 /* Update the current history entry before to
2767 * overwrite it with the next one. */
2768 free(history[history_len - 1 - l->history_index]);
2769 history[history_len - 1 - l->history_index] = strdup(l->buf);
2770 /* Show the new entry */
2771 l->history_index += (history_index < (history_len - 1 - l->history_index)) ? 1 : -1;
2772 if (l->history_index < 0) {
2773 l->history_index = 0;
2774 break;
2775 } else if (l->history_index >= history_len) {
2776 l->history_index = history_len - 1;
2777 break;
2778 }
2779 strncpy(l->buf, history[history_len - 1 - l->history_index], l->buflen);
2780 l->buf[l->buflen - 1] = '\0';
2781 l->len = strlen(l->buf);
2782 if (!hasMatches) {
2783 l->pos = l->len;
2784 } else {
2785 l->pos = l->search_matches[l->search_index].match_end;
2786 }
2787 }
2788
2789 if (nextCommand == ENTER) {
2790 l->pos = l->len;
2791 }
2792
2793 cancelSearch(l);
2794 return nextCommand;
2795}
2796
2797static void performSearch(linenoiseState* l) {
2798 // we try to maintain the current match while searching

Callers 1

linenoiseSearchFunction · 0.85

Calls 3

strdupFunction · 0.85
cancelSearchFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected