-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
limit show elements in list and highlight of user mentioned #91
Open
alfy91
wants to merge
4
commits into
fritx:dev
Choose a base branch
from
alfy91:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,10 +46,6 @@ export default { | |
type: Boolean, | ||
default: true | ||
}, | ||
members: { | ||
type: Array, | ||
default: () => [] | ||
}, | ||
nameKey: { | ||
type: String, | ||
default: '' | ||
|
@@ -71,6 +67,14 @@ export default { | |
scrollRef: { | ||
type: String, | ||
default: '' | ||
}, | ||
maxLoadUsers: { | ||
type: Number, | ||
default: 10 | ||
}, | ||
enableHighlight: { | ||
type: Boolean, | ||
default: true | ||
} | ||
}, | ||
|
||
|
@@ -81,12 +85,13 @@ export default { | |
bindsValue: this.value != null, | ||
customsEmbedded: false, | ||
hasComposition: false, | ||
atwho: null | ||
atwho: null, | ||
type: "" | ||
} | ||
}, | ||
computed: { | ||
atItems () { | ||
return this.at ? [this.at] : this.ats | ||
return this.ats.map(at => at.symbol) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obviously, change like this is something breaking, against all the versions before this, and will influenced all the users who use this library. |
||
}, | ||
|
||
currentItem () { | ||
|
@@ -165,6 +170,17 @@ export default { | |
handleDelete (e) { | ||
const range = getPrecedingRange() | ||
if (range) { | ||
var node = range.commonAncestorContainer.parentNode; | ||
/** | ||
* When you remove a char of a computed element, it is necessary remove | ||
* all the html element. | ||
*/ | ||
if(node.tagName == "SPAN" && node.classList.contains("at-computed")) { | ||
node.remove(); | ||
e.preventDefault() | ||
e.stopPropagation() | ||
return; | ||
} | ||
// fixme: Very bad code from me | ||
if (this.customsEmbedded && range.endOffset >= 1) { | ||
let a = range.endContainer.childNodes[range.endOffset] | ||
|
@@ -235,7 +251,8 @@ export default { | |
} | ||
return | ||
} | ||
if (e.keyCode === 13 || (this.tabSelect && e.keyCode === 9)) { // enter or tab | ||
var onlyInSet = this.ats[this.atItems.indexOf(this.type)].onlyInSet | ||
if (e.keyCode === 13 || (this.tabSelect && e.keyCode === 9) || (e.keyCode === 32 && !onlyInSet)) { // enter or tab or space if i can accept words not in the set. | ||
this.insertItem() | ||
e.preventDefault() | ||
e.stopPropagation() | ||
|
@@ -282,7 +299,9 @@ export default { | |
const text = range.toString() | ||
|
||
const { at, index } = getAtAndIndex(text, atItems) | ||
|
||
var startedCharIndex = this.atItems.indexOf(at); | ||
this.members = this.ats[startedCharIndex].data; | ||
this.type = at; | ||
if (index < 0) show = false | ||
const prev = text[index - 1] | ||
|
||
|
@@ -312,10 +331,20 @@ export default { | |
const name = itemName(v) | ||
return filterMatch(name, chunk, at) | ||
}) | ||
/** | ||
* If the following property is true, the component not accept other | ||
* different values. | ||
*/ | ||
var onlyInSet = this.ats[this.atItems.indexOf(this.type)].onlyInSet | ||
if(matched.length == 0 && !onlyInSet) { | ||
matched.push({ | ||
name: "#" + chunk | ||
}); | ||
} | ||
if (matched.length) { | ||
this.openPanel(matched, range, index, at) | ||
this.openPanel(matched, range, index, at) | ||
} else { | ||
this.closePanel() | ||
this.closePanel() | ||
} | ||
} | ||
} | ||
|
@@ -327,6 +356,9 @@ export default { | |
} | ||
}, | ||
openPanel (list, range, offset, at) { | ||
if(this.maxLoadUsers != -1) { | ||
list = list.slice(0,this.maxLoadUsers); | ||
} | ||
const fn = () => { | ||
const r = range.cloneRange() | ||
r.setStart(r.endContainer, offset + at.length) // 从@后第一位开始 | ||
|
@@ -392,6 +424,38 @@ export default { | |
r.collapse(false) // 参数在IE下必传 | ||
applyRange(r) | ||
}, | ||
insertMentions(text, r) { | ||
r.deleteContents(); | ||
|
||
var e = r.endContainer; | ||
var chars = e.data.split(""); | ||
var last = r.startOffset - 1; | ||
|
||
var classes = this.ats[this.atItems.indexOf(this.type)].cssClass; | ||
while (chars[last] != this.type && last > -1) { | ||
last--; | ||
} | ||
var after = e.data.substr(r.startOffset); | ||
e.data = e.data.substr(0, last); | ||
var parent = r.startContainer.parentElement; | ||
while(parent.tagName!="DIV" && parent.hasAttribute("contenteditable")){ | ||
parent = parent.parentElement; | ||
} | ||
var highlightElement = document.createElement("span"); | ||
highlightElement.innerText = text.trim(); | ||
highlightElement.className += classes; | ||
highlightElement.classList.add("at-computed") | ||
parent.appendChild(highlightElement); | ||
|
||
var space = document.createElement("span"); | ||
space.innerHTML = " " + after; | ||
parent.appendChild(space); | ||
r.setEndAfter(space); | ||
|
||
this.handleInput(); | ||
applyRange(r); | ||
r.collapse(false); | ||
}, | ||
|
||
insertHtml (html, r) { | ||
r.deleteContents() | ||
|
@@ -445,8 +509,13 @@ export default { | |
const html = this.$refs.embeddedItem.firstChild.innerHTML | ||
this.insertHtml(html, r); | ||
} else { | ||
const t = itemName(curItem) + suffix | ||
this.insertText(t, r); | ||
const t = itemName(curItem) + suffix; | ||
if(this.enableHighlight) { | ||
this.insertMentions(t, r); | ||
} else { | ||
this.insertText(t,r); | ||
} | ||
|
||
} | ||
|
||
this.$emit('insert', curItem) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piscitelli91 I'm confused why the prop of
members
is deleted 😕 it will break the members passing inThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, i knought that the pull request send my branch at the date of pull request and not for future commits (I'm working on new functions that I will discuss with you).
I will create a new branch until this commit: 9196ffe
Sorry for mistake :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piscitelli91 that would be cool, otherwise, I'm also trying to merge with fix if possible