Skip to content

KB : comment linked to text selection - #24944

Open
f2cmb wants to merge 41 commits into
glpi-project:mainfrom
f2cmb:kb/article/commentPart
Open

KB : comment linked to text selection#24944
f2cmb wants to merge 41 commits into
glpi-project:mainfrom
f2cmb:kb/article/commentPart

Conversation

@f2cmb

@f2cmb f2cmb commented Jul 24, 2026

Copy link
Copy Markdown
Contributor
  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.

Description

Selecting text, in read mode or in the editor, shows a Comment button that opens the Comments panel with the passage pre-filled. Anchored comments underline their passage; clicking a highlight scrolls to the thread.

An anchor stores what was selected rather than where (prefix / exact / suffix / occurrence, a W3C TextQuoteSelector)
and is relocated at display time, so editing around the passage keeps it valid. If the passage is deleted, the comment remains without highlight or quote. The same logic runs on the DOM in read mode and on the ProseMirror doc in edit mode, where highlights are decorations rather than marks so saved HTML and revision history stay unchanged.

Server side : 4 nullable columns on glpi_knowbaseitems_comments (additive migration), anchors restricted to root comments in prepareInputForAdd(), no new right (existing canComment() guard).

Screenshots :

image

@f2cmb f2cmb linked an issue Jul 27, 2026 that may be closed by this pull request
@f2cmb
f2cmb force-pushed the kb/article/commentPart branch from b1cb4ce to 350e5e5 Compare July 27, 2026 09:40
f2cmb added 28 commits July 27, 2026 14:14
@f2cmb
f2cmb force-pushed the kb/article/commentPart branch from 008caed to cd08f3f Compare July 27, 2026 12:15
@f2cmb
f2cmb marked this pull request as ready for review July 27, 2026 13:14
@f2cmb f2cmb added this to the 12.0.0 milestone Jul 27, 2026
Comment thread install/mysql/glpi-empty.sql Outdated
Comment thread templates/pages/tools/kb/sidepanel/comments_thread.html.twig
Comment thread js/modules/Knowbase/ReadModeSelectionBubble.js

let response;
try {
response = await post(`Knowbase/${this.#getKbId()}/AddComment`, body);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an error occurs, the comment button does not return to its original state (kept loader icon, which btw looks broken when reduced motion is requested because it doesn't spin then).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reset was after the await instead of in a finally. Same bug on the comment-edit path, fixed both.
Reduced motion isn't specific to this button: FontAwesome 7 kills .fa-spin entirely, and ti-loader-2 is a partial arc so it freezes into something broken-looking. 8 occurrences across templates/, 3 outside the KB. Separate issue rather than fixing only ours ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer not using .fa-spin at all. See #18752

The .icon-rotate class still works with reduced motion.

It would be nice if we could eventually drop FontAwesome completely, but it sticks around because some user features allowed selecting FA icons for things.

Comment thread js/modules/Knowbase/DomTextIndex.js
Comment thread js/modules/Knowbase/DomTextIndex.js

/* global TiptapCore, TiptapPMState, TiptapPMView */

import { locateAnchor, overlaps } from '/js/modules/Knowbase/CommentAnchor.js';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Editing content that is part of the comment's anchor text breaks the comment link. The anchor data still exists in the DB but is is no longer valid.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, the stale row was the real issue. Editing the passage away now drops the anchor on save, so nothing lingers. The comment survives as a plain one. Text matching can't make a broken anchor recoverable, which is another argument for your mark model.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure how it should work for GLPI. In Outline, editing the text obviously keeps the link while removing all of the linked text removed the link while preserving the comment.

@cedric-anne
cedric-anne requested a review from orthagh July 29, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comment on specific part of the article

2 participants