String (@NotNull CustomTemplateCallback callback) { int offset = callback.getEditor().getCaretModel().getOffset(); CharSequence charsSequence = callback.getEditor().getDocument().getImmutableCharSequence(); for (TextMateSnippet snippet : getAvailableSnippets(callback.getEditor())) { String key = snippet.getKey(); if (key.length() <= offset && StringUtil.equals(key, charsSequence.subSequence(offset - key.length(), offset))) { return key; } } return null; }