export function getPattern(value, caretPosition, substrToTheEnd = false) {
  let start = -1;
  let i = caretPosition;
  while (i >= 0 && start < 0) {
    if (value[i] === '$') {
      start = i;
    }
    i--;
  }

  return value
    .substring(start, substrToTheEnd ? undefined : caretPosition)
    .trim();
}

export function getValueWithSuggestion(suggestion, caretCursor, fullText) {
  
  let start = -1;
  let end = -1;

  let i = caretCursor;
  while (i >= 0 && start < 0) {
    if (fullText[i] === '$') {
      start = i;
    }
    i--;
  }
  i = caretCursor - 1;
  while (i <= fullText.length && end < 0) {
    if (fullText[i] === '$') {
      end = i;
    } else if (fullText[i] === ' ') {
      end = i - 1;
    }
    i++;
  }

  if (end < 0) {
    end = fullText.length;
  }

  const prefix = fullText.substr(0, start - 1);
  const suffix = '';
  const prefixSeparator = prefix ? ' $' : '$';
  const suffixSeparator = suffix ? '$ ' : '$';
  return [
    ...prefix,
    prefixSeparator,
    suggestion,
    suffixSeparator,
    ...suffix.trimLeft(),
  ].join('');
}

export function getStartValueWithSuggestion(caretCursor, fullText) {
  
  let start = -1;
  let end = -1;

  let i = caretCursor;
  while (i >= 0 && start < 0) {
    if (fullText[i] === '$') {
      start = i;
    }
    i--;
  }
  i = caretCursor - 1;
  while (i <= fullText.length && end < 0) {
    if (fullText[i] === '$') {
      end = i;
    } else if (fullText[i] === ' ') {
      end = i - 1;
    }
    i++;
  }

  if (end < 0) {
    end = fullText.length;
  }


  return start;
}

@@ -373,34 +373,32 @@
 or, fullText) %7B%0A
-  
 %0A  let start = -
@@ -777,16 +777,18 @@
 th;%0A  %7D%0A
+  
 %0A  const
@@ -821,20 +821,16 @@
 0, start
- - 1
 );%0A  con
@@ -882,16 +882,10 @@
 fix 
-? ' $' :
+&&
  '$'
@@ -933,16 +933,19 @@
  : '$';%0A
+  %0A
   return

Change behaviour when clicking suggested Variables so prefix remains