@@ -34,7 +34,7 @@ import {
3434 PixelsPerInch ,
3535 stopEvent ,
3636} from "../display_utils.js" ;
37- import { HighlightToolbar } from "./toolbar.js" ;
37+ import { FloatingToolbar } from "./toolbar.js" ;
3838
3939function bindEvents ( obj , element , names ) {
4040 for ( const name of names ) {
@@ -631,7 +631,7 @@ class AnnotationEditorUIManager {
631631
632632 #highlightWhenShiftUp = false ;
633633
634- #highlightToolbar = null ;
634+ #floatingToolbar = null ;
635635
636636 #idManager = new IdManager ( ) ;
637637
@@ -908,8 +908,8 @@ class AnnotationEditorUIManager {
908908 this . #altTextManager?. destroy ( ) ;
909909 this . #commentManager?. destroy ( ) ;
910910 this . #signatureManager?. destroy ( ) ;
911- this . #highlightToolbar ?. hide ( ) ;
912- this . #highlightToolbar = null ;
911+ this . #floatingToolbar ?. hide ( ) ;
912+ this . #floatingToolbar = null ;
913913 this . #mainHighlightColorPicker?. destroy ( ) ;
914914 this . #mainHighlightColorPicker = null ;
915915 if ( this . #focusMainContainerTimeoutId) {
@@ -1157,7 +1157,7 @@ class AnnotationEditorUIManager {
11571157 return null ;
11581158 }
11591159
1160- highlightSelection ( methodOfCreation = "" ) {
1160+ highlightSelection ( methodOfCreation = "" , comment = false ) {
11611161 const selection = document . getSelection ( ) ;
11621162 if ( ! selection || selection . isCollapsed ) {
11631163 return ;
@@ -1175,7 +1175,7 @@ class AnnotationEditorUIManager {
11751175 const layer = this . #getLayerForTextLayer( textLayer ) ;
11761176 const isNoneMode = this . #mode === AnnotationEditorType . NONE ;
11771177 const callback = ( ) => {
1178- layer ?. createAndAddNewEditor ( { x : 0 , y : 0 } , false , {
1178+ const editor = layer ?. createAndAddNewEditor ( { x : 0 , y : 0 } , false , {
11791179 methodOfCreation,
11801180 boxes,
11811181 anchorNode,
@@ -1187,6 +1187,9 @@ class AnnotationEditorUIManager {
11871187 if ( isNoneMode ) {
11881188 this . showAllEditors ( "highlight" , true , /* updateButton = */ true ) ;
11891189 }
1190+ if ( comment ) {
1191+ editor ?. editComment ( ) ;
1192+ }
11901193 } ;
11911194 if ( isNoneMode ) {
11921195 this . switchToMode ( AnnotationEditorType . HIGHLIGHT , callback ) ;
@@ -1195,7 +1198,11 @@ class AnnotationEditorUIManager {
11951198 callback ( ) ;
11961199 }
11971200
1198- #displayHighlightToolbar( ) {
1201+ commentSelection ( methodOfCreation = "" ) {
1202+ this . highlightSelection ( methodOfCreation , /* comment */ true ) ;
1203+ }
1204+
1205+ #displayFloatingToolbar( ) {
11991206 const selection = document . getSelection ( ) ;
12001207 if ( ! selection || selection . isCollapsed ) {
12011208 return ;
@@ -1206,8 +1213,8 @@ class AnnotationEditorUIManager {
12061213 if ( ! boxes ) {
12071214 return ;
12081215 }
1209- this . #highlightToolbar ||= new HighlightToolbar ( this ) ;
1210- this . #highlightToolbar . show ( textLayer , boxes , this . direction === "ltr" ) ;
1216+ this . #floatingToolbar ||= new FloatingToolbar ( this ) ;
1217+ this . #floatingToolbar . show ( textLayer , boxes , this . direction === "ltr" ) ;
12111218 }
12121219
12131220 /**
@@ -1241,7 +1248,7 @@ class AnnotationEditorUIManager {
12411248 const selection = document . getSelection ( ) ;
12421249 if ( ! selection || selection . isCollapsed ) {
12431250 if ( this . #selectedTextNode) {
1244- this . #highlightToolbar ?. hide ( ) ;
1251+ this . #floatingToolbar ?. hide ( ) ;
12451252 this . #selectedTextNode = null ;
12461253 this . #dispatchUpdateStates( {
12471254 hasSelectedText : false ,
@@ -1258,7 +1265,7 @@ class AnnotationEditorUIManager {
12581265 const textLayer = anchorElement . closest ( ".textLayer" ) ;
12591266 if ( ! textLayer ) {
12601267 if ( this . #selectedTextNode) {
1261- this . #highlightToolbar ?. hide ( ) ;
1268+ this . #floatingToolbar ?. hide ( ) ;
12621269 this . #selectedTextNode = null ;
12631270 this . #dispatchUpdateStates( {
12641271 hasSelectedText : false ,
@@ -1267,7 +1274,7 @@ class AnnotationEditorUIManager {
12671274 return ;
12681275 }
12691276
1270- this . #highlightToolbar ?. hide ( ) ;
1277+ this . #floatingToolbar ?. hide ( ) ;
12711278 this . #selectedTextNode = anchorNode ;
12721279 this . #dispatchUpdateStates( {
12731280 hasSelectedText : true ,
@@ -1315,7 +1322,7 @@ class AnnotationEditorUIManager {
13151322 if ( this . #mode === AnnotationEditorType . HIGHLIGHT ) {
13161323 this . highlightSelection ( methodOfCreation ) ;
13171324 } else if ( this . #enableHighlightFloatingButton) {
1318- this . #displayHighlightToolbar ( ) ;
1325+ this . #displayFloatingToolbar ( ) ;
13191326 }
13201327 }
13211328
@@ -1606,6 +1613,9 @@ class AnnotationEditorUIManager {
16061613 case "highlightSelection" :
16071614 this . highlightSelection ( "context_menu" ) ;
16081615 break ;
1616+ case "commentSelection" :
1617+ this . commentSelection ( "context_menu" ) ;
1618+ break ;
16091619 }
16101620 }
16111621
0 commit comments