wavesoft / local-echo

A local-echo controller for xterm.js
Apache License 2.0
142 stars 71 forks source link

Autocompletehandler pasting full command instead of completing the written command #49

Closed skast96 closed 2 years ago

skast96 commented 2 years ago

Hello

as the title says the autocomplete is pasting the whole command into the input instead of completing it. Example:

My commands:

defaultCommands: [
      "print test",
      "print pip list",
    ],

My Autocomplete:

 this.localEcho.addAutocompleteHandler((index, tokens) => {
        if (index !== 0) {
          let possible = this.defaultCommands;
          for (let command of tokens) {
            possible = possible.filter(element => element.includes(command));
          }
          return possible;
        }
        return this.defaultCommands;
      });

The text in the input:

print p **TAB TAB**

Results in:

print p print pip list

Is there a nice and simple solution for that?

skast96 commented 2 years ago

Fixed it on my own just look at my fork if you need that behavior too.

benelliott commented 5 months ago

The above mentioned fork seems to have been deleted. For anyone else who had this problem, my solution was to change the following around line 584 of LocalEchoController.js:

            } else if (candidates.length <= this.maxAutocompleteEntries) {

              // search for a shared fragement
              const sameFragment = getSharedFragment(inputFragment, candidates);

              // if there's a shared fragement between the candidates
              // print complete the shared fragment
              if (sameFragment) {
                const lastToken = getLastToken(inputFragment);
                this.handleCursorInsert(
                  sameFragment.substr(lastToken.length)
                );
              }
          to
            } else if (candidates.length <= this.maxAutocompleteEntries) {
              const lastInputToken = getLastToken(inputFragment);
              // search for a shared fragement
              const sameFragment = getSharedFragment(lastInputToken, candidates);

              // if there's a shared fragement between the candidates
              // print complete the shared fragment
              if (sameFragment) {
                this.handleCursorInsert(
                  sameFragment.substr(lastInputToken.length)
                );
              }