From 32e0396b3e8c414901a05460dd7cdc45eb50fc0c Mon Sep 17 00:00:00 2001 From: ian Date: Thu, 2 Dec 2021 00:14:09 +0800 Subject: [PATCH] Improve mentions keyboard accessibility (#10173) * Improve keyboard accessibility * Add check for up down keys * Add newline check for triggering * Allow keyboard insertion of users * Clear positional node errors on safari * Add a little sanity check to please automated code checkers * Use active instead of dashed Co-authored-by: rijkvanzanten --- api/src/services/activity.ts | 8 +- app/src/components/v-template-input.vue | 213 ++++++++++++++++-- .../comments-sidebar-detail/comment-input.vue | 45 +++- .../comments-sidebar-detail.vue | 2 +- 4 files changed, 239 insertions(+), 29 deletions(-) diff --git a/api/src/services/activity.ts b/api/src/services/activity.ts index fb7f704ebc..64ef0be871 100644 --- a/api/src/services/activity.ts +++ b/api/src/services/activity.ts @@ -10,6 +10,7 @@ import logger from '../logger'; import { userName } from '../utils/user-name'; import { uniq } from 'lodash'; import env from '../env'; +import validateUUID from 'uuid-validate'; export class ActivityService extends ItemsService { notificationsService: NotificationsService; @@ -66,10 +67,13 @@ export class ActivityService extends ItemsService { let comment = data.comment; for (const mention of mentions) { - comment = comment.replace(mention, userPreviews[mention.substring(1)] ?? '@Unknown User'); + const uuid = mention.substring(1); + // We only match on UUIDs in the first place. This is just an extra sanity check + if (validateUUID(uuid) === false) continue; + comment = comment.replace(new RegExp(mention, 'gm'), userPreviews[uuid] ?? '@Unknown User'); } - comment = `> ${comment}`; + comment = `> ${comment.replace(/\n+/gm, '\n> ')}`; const message = ` Hello ${userName(user)}, diff --git a/app/src/components/v-template-input.vue b/app/src/components/v-template-input.vue index 419c684248..5bab5e23f3 100644 --- a/app/src/components/v-template-input.vue +++ b/app/src/components/v-template-input.vue @@ -10,7 +10,7 @@ diff --git a/app/src/views/private/components/comments-sidebar-detail/comments-sidebar-detail.vue b/app/src/views/private/components/comments-sidebar-detail/comments-sidebar-detail.vue index 4a727cff80..8c5ad6cf9a 100644 --- a/app/src/views/private/components/comments-sidebar-detail/comments-sidebar-detail.vue +++ b/app/src/views/private/components/comments-sidebar-detail/comments-sidebar-detail.vue @@ -109,7 +109,7 @@ export default defineComponent({ return { ...comment, - display: newCommentText, + display: newCommentText.replaceAll('\n', '
'), }; });