mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
fix(chat): better @ searching, no chat card borders
This commit is contained in:
@@ -68,8 +68,10 @@ export default {
|
|||||||
props: ['selections', 'text', 'coords', 'chat', 'textbox'],
|
props: ['selections', 'text', 'coords', 'chat', 'textbox'],
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
atRegex: new RegExp(/@[\w-]+$/),
|
||||||
currentSearch: '',
|
currentSearch: '',
|
||||||
searchActive: false,
|
searchActive: false,
|
||||||
|
searchEscaped: false,
|
||||||
currentSearchPosition: 0,
|
currentSearchPosition: 0,
|
||||||
tmpSelections: [],
|
tmpSelections: [],
|
||||||
icons: Object.freeze({
|
icons: Object.freeze({
|
||||||
@@ -106,7 +108,10 @@ export default {
|
|||||||
},
|
},
|
||||||
searchResults () {
|
searchResults () {
|
||||||
if (!this.searchActive) return [];
|
if (!this.searchActive) return [];
|
||||||
let currentSearch = this.text.substring(this.currentSearchPosition + 1, this.text.length);
|
if (!this.atRegex.exec(this.text)) return [];
|
||||||
|
let currentSearch = this.atRegex.exec(this.text)[0];
|
||||||
|
currentSearch = currentSearch.substring(1, currentSearch.length);
|
||||||
|
|
||||||
return this.tmpSelections.filter((option) => {
|
return this.tmpSelections.filter((option) => {
|
||||||
return option.displayName.toLowerCase().indexOf(currentSearch.toLowerCase()) !== -1 || option.username && option.username.toLowerCase().indexOf(currentSearch.toLowerCase()) !== -1;
|
return option.displayName.toLowerCase().indexOf(currentSearch.toLowerCase()) !== -1 || option.username && option.username.toLowerCase().indexOf(currentSearch.toLowerCase()) !== -1;
|
||||||
}).slice(0, 4);
|
}).slice(0, 4);
|
||||||
@@ -116,13 +121,27 @@ export default {
|
|||||||
mounted () {
|
mounted () {
|
||||||
this.grabUserNames();
|
this.grabUserNames();
|
||||||
},
|
},
|
||||||
|
created () {
|
||||||
|
document.addEventListener('keyup', this.handleEsc);
|
||||||
|
},
|
||||||
|
destroyed () {
|
||||||
|
document.removeEventListener('keyup', this.handleEsc);
|
||||||
|
},
|
||||||
watch: {
|
watch: {
|
||||||
text (newText) {
|
text (newText) {
|
||||||
if (!newText[newText.length - 1] || newText[newText.length - 1] === ' ') {
|
if (!newText[newText.length - 1] || newText[newText.length - 1] === ' ') {
|
||||||
this.searchActive = false;
|
this.searchActive = false;
|
||||||
|
this.searchEscaped = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
if (newText[newText.length - 1] === '@') {
|
||||||
|
this.searchActive = false;
|
||||||
|
this.searchEscaped = false;
|
||||||
|
}
|
||||||
|
if (this.searchEscaped) return;
|
||||||
|
|
||||||
|
if (!this.atRegex.test(newText)) return;
|
||||||
|
|
||||||
if (newText[newText.length - 2] !== '@') return;
|
|
||||||
this.searchActive = true;
|
this.searchActive = true;
|
||||||
this.currentSearchPosition = newText.length - 2;
|
this.currentSearchPosition = newText.length - 2;
|
||||||
},
|
},
|
||||||
@@ -137,6 +156,7 @@ export default {
|
|||||||
// the same parent component. So, reset the data
|
// the same parent component. So, reset the data
|
||||||
this.currentSearch = '';
|
this.currentSearch = '';
|
||||||
this.searchActive = false;
|
this.searchActive = false;
|
||||||
|
this.searchEscaped = false;
|
||||||
this.currentSearchPosition = 0;
|
this.currentSearchPosition = 0;
|
||||||
this.tmpSelections = [];
|
this.tmpSelections = [];
|
||||||
},
|
},
|
||||||
@@ -179,6 +199,12 @@ export default {
|
|||||||
this.searchActive = false;
|
this.searchActive = false;
|
||||||
this.$emit('select', newText);
|
this.$emit('select', newText);
|
||||||
},
|
},
|
||||||
|
handleEsc (e) {
|
||||||
|
if (e.keyCode === 27) {
|
||||||
|
this.searchActive = false;
|
||||||
|
this.searchEscaped = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mixins: [styleHelper],
|
mixins: [styleHelper],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -76,6 +76,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.card {
|
.card {
|
||||||
|
border: 0px;
|
||||||
margin-bottom: .5em;
|
margin-bottom: .5em;
|
||||||
padding: 0rem;
|
padding: 0rem;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user