omelette icon indicating copy to clipboard operation
omelette copied to clipboard

Change of 'word' breaks 'before' param

Open jblandry opened this issue 8 years ago • 11 comments

Hi, I tried to switch to 0.4.0 and the change of fetching method for word (https://github.com/f/omelette/commit/b74b23209f5b8254f0d28b120fdfbf034086c30c#diff-564d24cceffda49c18bf427e92b8baa3R23) makes the parameter before undefined when an incomplete word is tabbed.

Ex:

lorem <tab><tab>      -> a1 b1       👍 
lorem a<tab>          -> a1          👍
lorem a1 <tab><tab>   -> a2 b2 c2    👍
lorem a1 a<tab>       -> nothing     👎 

My script that goes like this

const autocomplete = {
  'a1': {
    'a2': {
      'a3': {
        'a4': {},
        'b4': {}
      },
      'b3': {}
    },
    'b2': {},
    'c2': {}
  },
  'b1': {
    'a2': {},
    'b2': {
      'a3': {
        'a4': {},
        'b4': {}
      },
      'b3': {}
    },
    'c2': {}
  }
};


const completion = omelette('lorem');

completion.on('$1', ({ reply }) => {
  reply(Object.keys(autocomplete));
});

completion.on('$2', ({ reply, before }) => {
  try {
    reply(Object.keys(autocomplete[before]));
  } catch (e) {}
});

completion.on('$3', ({ reply, before, line }) => {
  const [, lvl1] = line.split(' ');
  try {
    reply(Object.keys(autocomplete[lvl1][before]));
  } catch (e) {}
});

completion.on('$4', ({ reply, before, line }) => {
  const [, lvl1, lvl2] = line.split(' ');
  try {
    reply(Object.keys(autocomplete[lvl1][lvl2][before]));
  } catch (e) {}
});

completion.init();

jblandry avatar May 06 '17 13:05 jblandry

-Out of context-

This tree thingy made me excited! Very nice idea! I wrote a PoC for Omelette to support tree syntax.

Can you check https://github.com/f/omelette/tree/completion-tree#autocompletion-tree?

f avatar May 06 '17 15:05 f

The problem still exists btw, I'll check it out.

f avatar May 06 '17 15:05 f

Ups, accidentally closed :)

f avatar May 06 '17 15:05 f

Wow this is way more than I asked for! Works really well and simplifies my implementation. Kudos 👍

jblandry avatar May 07 '17 13:05 jblandry

Wdyt should i merge it?

7 May 2017 Paz 16:34 tarihinde Jb [email protected] şunu yazdı:

Wow this is way more than I asked for! Works really well and simplifies my implementation. Kudos 👍

— You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub https://github.com/f/omelette/issues/10#issuecomment-299706724, or mute the thread https://github.com/notifications/unsubscribe-auth/AAL_ffFoieFVi9l0pV3HKXIKiyNkyA6rks5r3ch1gaJpZM4NSwdx .

f avatar May 07 '17 13:05 f

Hell yeah!

jblandry avatar May 07 '17 13:05 jblandry

https://github.com/f/omelette/blob/master/README.md#autocompletion-tree 😍 Thank you @jblandry for this great improvement!

f avatar May 07 '17 19:05 f

FYI: The original bug is still there.

jblandry avatar Oct 05 '17 20:10 jblandry

Sorry about it, can you explain the original bug again please?

f avatar Oct 05 '17 21:10 f

Everything is in the first post of this thread :)

jblandry avatar Oct 06 '17 12:10 jblandry

Just hit this as well. My workaround is to implement before manually using line, but i'd really rather not to

TxHawks avatar Dec 30 '18 21:12 TxHawks