source/index.js
/**
 * Function moves a note following the cursor
 */
Function moves a note following the cursor
Function moves a note following the cursor
function moveNote() {
  let lastPosition = noteWrapper.selectedIndex;
  function listener(ch, key) {
    if (
      key.name === 'k' ||
      key.name === 'j' ||
      key.name === 'up' ||
      key.name === 'down'
    ) {
      let currentPosition = noteWrapper.selectedIndex;
      notes.swap(currentPosition, lastPosition);
      lastPosition = currentPosition;
      noteWrapper.setItems(
        notes.toArray().map((entry, index) => `${index + 1}) ${entry}`)
      );
      screen.render();
    }
  }
  if (noteWrapper.moving === true) {
    noteWrapper.moving = false;
    noteWrapper.style.selected.bg = theme.focusColor;
    noteWrapper.removeListener('keypress', listener);
    screen.render();
  } else {
    noteWrapper.moving = true;
    noteWrapper.style.selected.bg = theme.selectedColor;
    infoWrapper.content = `moving a note... press 'M' again to cancel`;
    noteWrapper.focus();
    screen.render();
    lastPosition = noteWrapper.selectedIndex;
    noteWrapper.on('keypress', listener);
  }
}
function moveNote ( ) { let lastPosition = noteWrapper . selectedIndex ; function listener ( ch , key ) { if ( key . name === 'k' || key . name === 'j' || key . name === 'up' || key . name === 'down' ) { let currentPosition = noteWrapper . selectedIndex ; notes . swap ( currentPosition , lastPosition ) ; lastPosition = currentPosition ; noteWrapper . setItems ( notes . toArray ( ) . map ( ( entry , index ) => ` ${ index + 1 } ${ entry } ` ) ) ; screen . render ( ) ; } } if ( noteWrapper . moving === true ) { noteWrapper . moving = false ; noteWrapper . style . selected . bg = theme . focusColor ; noteWrapper . removeListener ( 'keypress' , listener ) ; screen . render ( ) ; } else { noteWrapper . moving = true ; noteWrapper . style . selected . bg = theme . selectedColor ; infoWrapper . content = ` ` ; noteWrapper . focus ( ) ; screen . render ( ) ; lastPosition = noteWrapper . selectedIndex ; noteWrapper . on ( 'keypress' , listener ) ; } }
Function moves a note following the cursor
Function moves a note following the cursor
/* Stop moving */ /* Start moving */