@@ -90,6 +90,8 @@ class AnnotationEditor {
9090
9191 #touchManager = null ;
9292
93+ isSelected = false ;
94+
9395 _isCopy = false ;
9496
9597 _editToolbar = null ;
@@ -1170,7 +1172,7 @@ class AnnotationEditor {
11701172 const [ tx , ty ] = this . getInitialTranslation ( ) ;
11711173 this . translate ( tx , ty ) ;
11721174
1173- bindEvents ( this , div , [ "keydown" , "pointerdown" ] ) ;
1175+ bindEvents ( this , div , [ "keydown" , "pointerdown" , "dblclick" ] ) ;
11741176
11751177 if ( this . isResizable && this . _uiManager . _supportsPinchToZoom ) {
11761178 this . #touchManager ||= new TouchManager ( {
@@ -1279,10 +1281,6 @@ class AnnotationEditor {
12791281 this . #selectOnPointerEvent( event ) ;
12801282 }
12811283
1282- get isSelected ( ) {
1283- return this . _uiManager . isSelected ( this ) ;
1284- }
1285-
12861284 #selectOnPointerEvent( event ) {
12871285 const { isMac } = FeatureTest . platform ;
12881286 if (
@@ -1499,16 +1497,30 @@ class AnnotationEditor {
14991497
15001498 /**
15011499 * Enable edit mode.
1500+ * @returns {boolean } - true if the edit mode has been enabled.
15021501 */
15031502 enableEditMode ( ) {
1503+ if ( this . isInEditMode ( ) ) {
1504+ return false ;
1505+ }
1506+ this . parent . setEditingState ( false ) ;
15041507 this . #isInEditMode = true ;
1508+
1509+ return true ;
15051510 }
15061511
15071512 /**
15081513 * Disable edit mode.
1514+ * @returns {boolean } - true if the edit mode has been disabled.
15091515 */
15101516 disableEditMode ( ) {
1517+ if ( ! this . isInEditMode ( ) ) {
1518+ return false ;
1519+ }
1520+ this . parent . setEditingState ( true ) ;
15111521 this . #isInEditMode = false ;
1522+
1523+ return true ;
15121524 }
15131525
15141526 /**
@@ -1832,6 +1844,10 @@ class AnnotationEditor {
18321844 * Select this editor.
18331845 */
18341846 select ( ) {
1847+ if ( this . isSelected && this . _editToolbar ) {
1848+ return ;
1849+ }
1850+ this . isSelected = true ;
18351851 this . makeResizable ( ) ;
18361852 this . div ?. classList . add ( "selectedEditor" ) ;
18371853 if ( ! this . _editToolbar ) {
@@ -1853,6 +1869,10 @@ class AnnotationEditor {
18531869 * Unselect this editor.
18541870 */
18551871 unselect ( ) {
1872+ if ( ! this . isSelected ) {
1873+ return ;
1874+ }
1875+ this . isSelected = false ;
18561876 this . #resizersDiv?. classList . add ( "hidden" ) ;
18571877 this . div ?. classList . remove ( "selectedEditor" ) ;
18581878 if ( this . div ?. contains ( document . activeElement ) ) {
@@ -1885,10 +1905,38 @@ class AnnotationEditor {
18851905 */
18861906 enableEditing ( ) { }
18871907
1908+ /**
1909+ * Check if the content of this editor can be changed.
1910+ * For example, a FreeText editor can be changed (the user can change the
1911+ * text), but a Stamp editor cannot.
1912+ * @returns {boolean }
1913+ */
1914+ get canChangeContent ( ) {
1915+ return false ;
1916+ }
1917+
18881918 /**
18891919 * The editor is about to be edited.
18901920 */
1891- enterInEditMode ( ) { }
1921+ enterInEditMode ( ) {
1922+ if ( ! this . canChangeContent ) {
1923+ return ;
1924+ }
1925+ this . enableEditMode ( ) ;
1926+ this . div . focus ( ) ;
1927+ }
1928+
1929+ /**
1930+ * ondblclick callback.
1931+ * @param {MouseEvent } event
1932+ */
1933+ dblclick ( event ) {
1934+ this . enterInEditMode ( ) ;
1935+ this . parent . updateToolbar ( {
1936+ mode : this . constructor . _editorType ,
1937+ editId : this . id ,
1938+ } ) ;
1939+ }
18921940
18931941 /**
18941942 * @returns {HTMLElement | null } the element requiring an alt text.
0 commit comments