comment_completion
MentionCompleter
Bases: QObject
Mention completion and highlighting for a QTextEdit.
Typing @, @@ or @@@ at the start of a word opens a popup listing the users, versions or tasks which can be mentioned. The picked item is inserted as a link, e.g. @@v003 linking to version:<id>, so the document's markdown contains [@@v003](version:<id>). Use :func:mentions_to_display and :func:mentions_to_storage to convert from and to the markdown stored on the server.
The versions and tasks don't have to be known up front: :attr:entities_requested is emitted each time the popup opens for them, to answer with :meth:set_entities whenever they are available.
Signals
entities_requested: The popup opened to mention a version or task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_edit | QTextEdit | The QTextEdit to complete mentions in. | required |
users | list[User] | None | Users which can be mentioned. | None |
Source code in client/ayon_core/ui/components/comment_completion.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 | |
clear_entities()
Forget the versions and tasks, e.g. of another version.
The popup shows them as loading until :meth:set_entities is called, which is asked for with :attr:entities_requested the next time the popup opens.
Source code in client/ayon_core/ui/components/comment_completion.py
384 385 386 387 388 389 390 391 392 393 394 395 396 | |
handle_key_press(event)
Complete the mention being typed or delete a mention as a whole.
Returns:
| Type | Description |
|---|---|
bool | True if the event was handled, False otherwise. |
Source code in client/ayon_core/ui/components/comment_completion.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
insert_trigger(trigger)
Type a trigger at the text cursor to open the popup.
A mention which is being typed is replaced, so the type of the mention can be switched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trigger | str |
| required |
Source code in client/ayon_core/ui/components/comment_completion.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |
popup_visible()
Whether the popup to pick a mention is open.
Source code in client/ayon_core/ui/components/comment_completion.py
398 399 400 | |
set_entities(versions=None, tasks=None)
Set the versions (@@) and tasks (@@@) to mention.
An open popup is updated, so this can be called at any time after :attr:entities_requested.
Source code in client/ayon_core/ui/components/comment_completion.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
set_users(users)
Set the users which can be mentioned with @.
Source code in client/ayon_core/ui/components/comment_completion.py
363 364 365 366 | |
MentionCompleterDelegate
Bases: QStyledItemDelegate
Display users with their icon and entities with their context.
Source code in client/ayon_core/ui/components/comment_completion.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
paint(painter, option, index)
Paint a user or entity which can be mentioned.
Source code in client/ayon_core/ui/components/comment_completion.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
sizeHint(option, index)
Return size hint for completer items.
Source code in client/ayon_core/ui/components/comment_completion.py
290 291 292 293 294 295 296 | |
MentionHighlighter
Bases: QSyntaxHighlighter
Syntax highlighter for mentions, raw URLs, and code spans.
Operates on block-local plain text so positions are always correct regardless of any rich-text formatting already present in the document (bold, italic, headings, code spans, etc.).
Patterns highlighted:
- Fenced code blocks (
\`\`\` ... \`\`\) spanning multiple lines - black background, white monospace text. Block state1tracks whether the current block is inside a fence. - Qt-rendered code blocks (from
setMarkdown()) — detected vianonBreakableLineson the block format. - Qt-rendered inline code spans (from
setMarkdown()) — detected viafontFixedPitchon individual text fragments. - Inline code spans (
\`code\`) in raw (un-rendered) text — same style, detected by backtick regex. - Links to
user:name,version:idortask:id— mentions inserted by :class:MentionCompleteror loaded from markdown. https?://…— raw URL
Text like @name which is not a link is not a mention and is not highlighted as one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document | The QTextDocument to attach to. | required |
Source code in client/ayon_core/ui/components/comment_completion.py
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 | |
highlightBlock(text)
Apply code, mention, and URL highlighting to a single block.
Two detection strategies are combined so that code is styled in both edit mode (raw markdown typed by the user) and display mode (rich text rendered via document().setMarkdown()):
Edit mode — raw fence markers: Uses block state 1 to track multi-line fenced code blocks. A line starting with ** opens or closes a fence; every line inside the fence is styled with :attr:`_code_fmt`. A line that both opens and closes a fence on the same line (e.g. ``\`\`\`code\`\`\) is treated as a single-line code block with no state change.
Display mode — Qt-rendered char formats: After setMarkdown() Qt strips the fence markers and stores rich text character formats. Fenced code blocks have nonBreakableLines=True set on the block format (fontFixedPitch stays False on the block-level char format). Inline code spans set fontFixedPitch=True on individual text fragments within a paragraph. Both are detected here and styled with :attr:_code_fmt.
Inline code spans from raw backtick syntax (\`code\`) are also detected via :attr:_P_CODE_INLINE for live-typed backtick spans.
Code formatting is applied after mention/URL patterns so that it takes precedence over any mention highlight inside a code span.
Called automatically by Qt whenever the block changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text | str | Plain text content of the current block. | required |
Source code in client/ayon_core/ui/components/comment_completion.py
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 | |
apply_code_block_backgrounds(text_edit)
Apply a full-width background colour to every fenced code block.
QSyntaxHighlighter.setFormat() only paints behind individual text characters, so the end of a short line keeps the regular widget background. Setting QTextBlockFormat.background instead causes Qt's own layout engine to paint the background across the entire width of the block before any characters are drawn.
This function is intentionally separate from :class:MentionHighlighter because Qt's documentation forbids modifying the document from inside highlightBlock().
Two detection strategies are combined so that code blocks are recognised in both scenarios:
- Display mode (after
document().setMarkdown()): Qt marks fenced code block lines withnonBreakableLines=Trueon the block format. - Edit mode (raw typing): Lines inside a
\`\`…\`\`\fence are detected by tracking an open-fence flag while iterating from the first block of the document.
The function is guarded by the _suppress_formatting attribute on text_edit to prevent infinite recursion: writing block formats emits contentsChanged, which would otherwise re-enter this function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_edit | QTextEdit | The QTextEdit whose document should have fenced code block backgrounds applied. | required |
Source code in client/ayon_core/ui/components/comment_completion.py
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 | |
is_mention_href(href)
Whether a link target refers to a mentioned user or entity.
Source code in client/ayon_core/ui/components/comment_completion.py
104 105 106 | |
mentions_to_display(md)
Prefix the label of stored mention links with their trigger.
[Joe](user:admin) becomes [@Joe](user:admin) and [v003](version:id) becomes [@@v003](version:id) so mentions are displayed the way they are typed. Code is left as it is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
md | str | Markdown text as stored on the server. | required |
Returns:
| Type | Description |
|---|---|
str | Markdown text to display. |
Source code in client/ayon_core/ui/components/comment_completion.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
mentions_to_storage(md)
Convert displayed mentions back to stored mention links.
Reverts :func:mentions_to_display. Only mentions picked from the completer are mentions: text like @Full Name typed without picking the user stays text, the same as in the web frontend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
md | str | Markdown text of the displayed document. | required |
Returns:
| Type | Description |
|---|---|
str | Markdown text to store on the server. |
Source code in client/ayon_core/ui/components/comment_completion.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |