Skip to content

Commit

Permalink
Add option for requiring leading space (#36)
Browse files Browse the repository at this point in the history
- Includes a rearrangement of arguments for the `getTriggerInfo` call in
  the `replaceTriggerText` method to match the `getTriggerInfo` method
  signature. This seemed to work fine before because
  all arguments were always `true` in that context.
  • Loading branch information
nickrivadeneira authored and mrsweaters committed Oct 27, 2016
1 parent a1f8568 commit 320962b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 39 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ Collection object shown with defaults:
fillAttr: 'value',

// REQUIRED: array of objects to match
values: []
values: [],

// specify whether a space is required before the trigger character
requireLeadingSpace: true
}
```

Expand Down
67 changes: 36 additions & 31 deletions dist/tribute.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tribute.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tribute.min.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions src/Tribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class Tribute {
fillAttr = 'value',
collection = null,
menuContainer = null,
noMatchTemplate = null
noMatchTemplate = null,
requireLeadingSpace = true
}) {

this.menuSelected = 0
Expand Down Expand Up @@ -56,7 +57,9 @@ class Tribute {
fillAttr: fillAttr,

// array of objects
values: values
values: values,

requireLeadingSpace: requireLeadingSpace
}]
}
else if (collection) {
Expand All @@ -77,7 +80,8 @@ class Tribute {
})(noMatchTemplate),
lookup: item.lookup || lookup,
fillAttr: item.fillAttr || fillAttr,
values: item.values
values: item.values,
requireLeadingSpace: item.requireLeadingSpace
}
})
}
Expand Down
6 changes: 4 additions & 2 deletions src/TributeRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class TributeRange {
let context = this.tribute.current
this.resetSelection(context.element, context.selectedPath, context.selectedOffset)

let info = this.getTriggerInfo(requireLeadingSpace, true, hasTrailingSpace)
let info = this.getTriggerInfo(true, hasTrailingSpace, requireLeadingSpace)

// Create the event
let replaceEvent = new CustomEvent('tribute-replaced', {
Expand Down Expand Up @@ -251,12 +251,14 @@ class TributeRange {
let mostRecentTriggerCharPos = -1
let triggerChar

this.tribute.triggers().forEach(c => {
this.tribute.collection.forEach(config => {
let c = config.trigger
let idx = effectiveRange.lastIndexOf(c)

if (idx > mostRecentTriggerCharPos) {
mostRecentTriggerCharPos = idx
triggerChar = c
requireLeadingSpace = config.requireLeadingSpace
}
})

Expand Down

0 comments on commit 320962b

Please sign in to comment.