@@ -10,7 +10,7 @@ import Annotation from '../../../annotationManagement/Annotation'
1010import Code from '../../model/Code'
1111// PVSCL:ENDCOND
1212import LanguageUtils from '../../../utils/LanguageUtils'
13- import ImageUtilsUtils from '../../../utils/ImageUtils '
13+ import ImageUtilsOCR from '../../../utils/ImageUtilsOCR '
1414
1515
1616class UpdateCodebook {
@@ -94,20 +94,28 @@ class UpdateCodebook {
9494 // Get user selected content
9595 let selection = document . getSelection ( )
9696 // If selection is child of sidebar, return null
97- if ( $ ( selection . anchorNode ) . parents ( '#annotatorSidebarWrapper' ) . toArray ( ) . length !== 0 || selection . toString ( ) . length < 1 ) {
98- if ( selection . anchorNode . innerText ) {
99- retrievedThemeName = selection . anchorNode . innerText
100- } else {
101- if ( selection . anchorNode . nodeName === 'IMG' ) {
102- retrievedThemeName = await ImageUtilsUtils . getStringFromImage ( selection . anchorNode )
97+ if ( selection . anchorNode ) {
98+ if ( $ ( selection . anchorNode ) . parents ( '#annotatorSidebarWrapper' ) . toArray ( ) . length !== 0 || selection . toString ( ) . length < 1 ) {
99+ if ( selection . anchorNode . innerText ) {
100+ retrievedThemeName = selection . anchorNode . innerText
103101 } else {
104- if ( selection . anchorNode . lastChild . nodeName === 'IMG' ) {
105- retrievedThemeName = await ImageUtilsUtils . getStringFromImage ( selection . anchorNode . lastChild )
102+ if ( selection . anchorNode . nodeName === 'IMG' ) {
103+ retrievedThemeName = await ImageUtilsOCR . getStringFromImage ( selection . anchorNode )
104+ } else {
105+ if ( selection . anchorNode . childNodes ) {
106+ let childArray = Array . from ( selection . anchorNode . childNodes )
107+ let imgChild = childArray . filter ( ( node ) => {
108+ return node . nodeName === 'IMG'
109+ } )
110+ if ( imgChild [ 0 ] ) {
111+ retrievedThemeName = await ImageUtilsOCR . getStringFromImage ( imgChild [ 0 ] )
112+ }
113+ }
106114 }
107115 }
116+ } else {
117+ retrievedThemeName = selection . toString ( ) . trim ( ) . replace ( / ^ \w / , c => c . toUpperCase ( ) )
108118 }
109- } else {
110- retrievedThemeName = selection . toString ( ) . trim ( ) . replace ( / ^ \w / , c => c . toUpperCase ( ) )
111119 }
112120 Alerts . multipleInputAlert ( {
113121 title : 'You are creating a new ' + Config . tags . grouped . group + ': ' ,
0 commit comments