@@ -15,9 +15,21 @@ export type SummarySvgGroup = SVGGElement & {
1515 summaryObj : Summary
1616}
1717
18- const calcRange = function ( currentNodes : Topic [ ] ) {
18+ const calcRange = function ( nodes : Topic [ ] ) {
19+ if ( nodes . length === 0 ) throw new Error ( 'No selected node.' )
20+ if ( nodes . length === 1 ) {
21+ const obj = nodes [ 0 ] . nodeObj
22+ const parent = nodes [ 0 ] . nodeObj . parent
23+ if ( ! parent ) throw new Error ( 'Can not select root node.' )
24+ const i = parent . children ! . findIndex ( child => obj === child )
25+ return {
26+ parent : parent . id ,
27+ start : i ,
28+ end : i ,
29+ }
30+ }
1931 let maxLen = 0
20- const parentChains = currentNodes . map ( item => {
32+ const parentChains = nodes . map ( item => {
2133 let node = item . nodeObj
2234 const parentChain = [ ]
2335 while ( node . parent ) {
@@ -34,7 +46,6 @@ const calcRange = function (currentNodes: Topic[]) {
3446 // find minimum common parent
3547 findMcp: for ( ; index < maxLen ; index ++ ) {
3648 const base = parentChains [ 0 ] [ index ] ?. node
37- console . log ( base )
3849 for ( let i = 1 ; i < parentChains . length ; i ++ ) {
3950 const parentChain = parentChains [ i ]
4051 if ( parentChain [ index ] ?. node !== base ) {
@@ -43,12 +54,10 @@ const calcRange = function (currentNodes: Topic[]) {
4354 }
4455 }
4556 const range = parentChains . map ( chain => chain [ index - 1 ] . index ) . sort ( )
46- console . log ( parentChains , 'parentChains' )
4757 const min = range [ 0 ] || 0
4858 const max = range [ range . length - 1 ] || 0
4959 const parent = parentChains [ 0 ] [ index - 1 ] . node
50- console . log ( parent )
51- // if (parent.root) throw new Error('Please select nodes in the same main topic.')
60+ if ( parent . root ) throw new Error ( 'Please select nodes in the same main topic.' )
5261
5362 // const start = parent.children![min].id
5463 // const end = parent.children![max].id
@@ -137,8 +146,13 @@ const drawSummary = function (mei: MindElixirInstance, summary: Summary) {
137146}
138147
139148export const createSummary = function ( this : MindElixirInstance ) {
140- if ( ! this . currentNodes ) return
141- const { parent, start, end } = calcRange ( this . currentNodes )
149+ let nodes : Topic [ ] = [ ]
150+ if ( this . currentNode ) {
151+ nodes = [ this . currentNode ]
152+ } else if ( this . currentNodes ) {
153+ nodes = this . currentNodes
154+ }
155+ const { parent, start, end } = calcRange ( nodes )
142156 const summary = { id : generateUUID ( ) , parent, start, end, text : 'summary' }
143157 const g = drawSummary ( this , summary ) as SummarySvgGroup
144158 this . summaries . push ( summary )
@@ -227,7 +241,6 @@ export const editSummary = function (this: MindElixirInstance, el: SummarySvgGro
227241 if ( ! div ) return
228242 const node = el . summaryObj
229243 const text = div . textContent ?. trim ( ) || ''
230- console . log ( text )
231244 if ( text === '' ) node . text = origin
232245 else node . text = text
233246 div . remove ( )
0 commit comments