@@ -90,6 +90,8 @@ class AnnotationEditor {
90
90
91
91
#touchManager = null ;
92
92
93
+ isSelected = false ;
94
+
93
95
_isCopy = false ;
94
96
95
97
_editToolbar = null ;
@@ -1170,7 +1172,7 @@ class AnnotationEditor {
1170
1172
const [ tx , ty ] = this . getInitialTranslation ( ) ;
1171
1173
this . translate ( tx , ty ) ;
1172
1174
1173
- bindEvents ( this , div , [ "keydown" , "pointerdown" ] ) ;
1175
+ bindEvents ( this , div , [ "keydown" , "pointerdown" , "dblclick" ] ) ;
1174
1176
1175
1177
if ( this . isResizable && this . _uiManager . _supportsPinchToZoom ) {
1176
1178
this . #touchManager ||= new TouchManager ( {
@@ -1279,10 +1281,6 @@ class AnnotationEditor {
1279
1281
this . #selectOnPointerEvent( event ) ;
1280
1282
}
1281
1283
1282
- get isSelected ( ) {
1283
- return this . _uiManager . isSelected ( this ) ;
1284
- }
1285
-
1286
1284
#selectOnPointerEvent( event ) {
1287
1285
const { isMac } = FeatureTest . platform ;
1288
1286
if (
@@ -1499,16 +1497,30 @@ class AnnotationEditor {
1499
1497
1500
1498
/**
1501
1499
* Enable edit mode.
1500
+ * @returns {boolean } - true if the edit mode has been enabled.
1502
1501
*/
1503
1502
enableEditMode ( ) {
1503
+ if ( this . isInEditMode ( ) ) {
1504
+ return false ;
1505
+ }
1506
+ this . parent . setEditingState ( false ) ;
1504
1507
this . #isInEditMode = true ;
1508
+
1509
+ return true ;
1505
1510
}
1506
1511
1507
1512
/**
1508
1513
* Disable edit mode.
1514
+ * @returns {boolean } - true if the edit mode has been disabled.
1509
1515
*/
1510
1516
disableEditMode ( ) {
1517
+ if ( ! this . isInEditMode ( ) ) {
1518
+ return false ;
1519
+ }
1520
+ this . parent . setEditingState ( true ) ;
1511
1521
this . #isInEditMode = false ;
1522
+
1523
+ return true ;
1512
1524
}
1513
1525
1514
1526
/**
@@ -1832,6 +1844,10 @@ class AnnotationEditor {
1832
1844
* Select this editor.
1833
1845
*/
1834
1846
select ( ) {
1847
+ if ( this . isSelected && this . _editToolbar ) {
1848
+ return ;
1849
+ }
1850
+ this . isSelected = true ;
1835
1851
this . makeResizable ( ) ;
1836
1852
this . div ?. classList . add ( "selectedEditor" ) ;
1837
1853
if ( ! this . _editToolbar ) {
@@ -1853,6 +1869,10 @@ class AnnotationEditor {
1853
1869
* Unselect this editor.
1854
1870
*/
1855
1871
unselect ( ) {
1872
+ if ( ! this . isSelected ) {
1873
+ return ;
1874
+ }
1875
+ this . isSelected = false ;
1856
1876
this . #resizersDiv?. classList . add ( "hidden" ) ;
1857
1877
this . div ?. classList . remove ( "selectedEditor" ) ;
1858
1878
if ( this . div ?. contains ( document . activeElement ) ) {
@@ -1885,10 +1905,38 @@ class AnnotationEditor {
1885
1905
*/
1886
1906
enableEditing ( ) { }
1887
1907
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
+
1888
1918
/**
1889
1919
* The editor is about to be edited.
1890
1920
*/
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
+ }
1892
1940
1893
1941
/**
1894
1942
* @returns {HTMLElement | null } the element requiring an alt text.
0 commit comments