Skip to content

Commit

Permalink
Fix snippets not working when hitting tab-key
Browse files Browse the repository at this point in the history
This fixes a long-standing regression introduced in 97d1319.
  • Loading branch information
Alhadis committed Feb 11, 2019
1 parent 45094a0 commit 59df84c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](http://semver.org).
* __Fixed:__ User-defined character names not highlighted by `\(xx`
* __Fixed:__ Macros starting with `.[` always assumed to be `refer(!)`
* __Fixed:__ Macros starting with `cu-` mistaken for `.cu` requests
* __Fixed:__ Snippets not working when hitting tab key
* __Improved:__ Highlighting of arithmetic and comparison operators
* __Removed:__ `.t` from associated file extensions

Expand Down
24 changes: 19 additions & 5 deletions lib/editing.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
module.exports = () => [
atom.commands.add("atom-text-editor[data-grammar='text roff']", {
"language-roff:fix-blank-lines": () => fixBlankLines(),
"language-roff:indent": () => indentEditor(),
"language-roff:outdent": () => outdentEditor(),
"language-roff:fix-blank-lines": ev => fixBlankLines(ev),
"language-roff:indent": ev => indentEditor(ev),
"language-roff:outdent": ev => outdentEditor(ev),
}),
];

Expand Down Expand Up @@ -39,11 +39,18 @@ function fixBlankLines(){

/**
* Handle Roff-specific indentation.
* @param {CustomEvent} event
* @internal
*/
function indentEditor(){
function indentEditor(event){
const ed = atom.workspace.getActiveTextEditor();

// Determine if snippet expansion is possible at the current cursor
const pkg = atom.packages.getActivePackage("snippets");
if(pkg && pkg.mainModule && "function" === typeof pkg.mainModule.snippetToExpandUnderCursor)
if(pkg.mainModule.snippetToExpandUnderCursor(ed) || pkg.mainModule.goToNextTabStop(ed))
return event.abortKeyBinding();

ed.transact(100, () => {
const tab = ed.getTabText();

Expand Down Expand Up @@ -77,11 +84,18 @@ function indentEditor(){

/**
* Handle Roff-specific unindentation.
* @param {CustomEvent} event
* @internal
*/
function outdentEditor(){
function outdentEditor(event){
const ed = atom.workspace.getActiveTextEditor();

// Terminate command if a snippet is active and a previous tabstop exists
const pkg = atom.packages.getActivePackage("snippets");
if(pkg && pkg.mainModule && "function" === typeof pkg.mainModule.goToPreviousTabStop)
if(pkg.mainModule.goToPreviousTabStop(ed))
return event.abortKeyBinding();

ed.transact(100, () => {
const tab = ed.getTabText();
const untab = "(?:\t|\\x20{1," + ed.getTabLength() + "})";
Expand Down

0 comments on commit 59df84c

Please sign in to comment.