Skip to content
This repository was archived by the owner on Jun 15, 2019. It is now read-only.

Commit 151d5f9

Browse files
committed
docs(main algorithm): Some useful comments were added to the main algorithm
Some useful comments were added to the main algorithm to explain the state of the work at each step.
1 parent 07b5b0c commit 151d5f9

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/TextWrap.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,35 @@ export default class TextWrap implements WrapStyle {
5454
// tslint:disable-next-line:label-position
5555
searchWhiteSpace: {
5656
if (vLen > this.wrapOn) { //logFastCheck(fastCheck)
57+
// 1. PASSED
5758
if (fastCheck ||
5859
// The 2nd condition will always be true if the 1st is true. Actually, it is the main condition
59-
// we need to check, but we know in most cases (~ 100%) the 1st is true.
60+
// we need to check, but we know in almost all cases the 1st (that is much simpler) is true.
6061
!(marker - start > indentsNVLen ||
6162
this.getVisualLength(text.slice(start, marker)) > indentsNVLen)
6263
// tslint:disable-next-line:no-conditional-assignment
6364
&& (fastCheck = true)
6465
) {
66+
// 1.1. PASSED but CAN'T
6567
logFastCheck(marker - start > indentsNVLen)
66-
if (isNotBreakable) continue mainLoop
68+
if (isNotBreakable) /* 1.1.1. PASSED but CAN'T and NO MARKER NEEDED */ continue mainLoop
69+
70+
// 1.1.2. PASSED but CAN'T and MARKER NEEDED
6771

6872
logFastCheck('')
6973
fastCheck = false
70-
} else if (isNotBreakable)
74+
} else /* 1.2. PASSED and CAN */ if (isNotBreakable) // 1.2.1. PASSED and CAN and MUST
7175
break searchWhiteSpace
72-
} else if (isNotBreakable)
76+
} else /* 2. NOT PASSED */ if (isNotBreakable) // 2.1. NOT PASSED and NO MARKER NEEDED
7377
continue mainLoop
7478

7579
// Any breakable character (white-space except '\n' and '\xA0'):
7680

81+
// 1.1.2. PASSED but CAN'T and MARKER NEEDED
82+
// 1.2.2. PASSED and CAN but MUST NOT
83+
// 2.2. NOT PASSED and MARKER NEEDED
84+
// => MARKER NEEDED
85+
7786
marker = i + 1 // Store the value of i
7887
vLen0 = vLen // Store the value of vLen
7988
continue mainLoop

0 commit comments

Comments
 (0)