Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,22 @@ import org.brailleblaster.math.template.Template.Companion.isTemplate
import org.brailleblaster.perspectives.braille.Manager
import org.brailleblaster.perspectives.braille.mapping.elements.BoxLineTextMapElement
import org.brailleblaster.perspectives.braille.mapping.elements.LineBreakElement
import org.brailleblaster.perspectives.braille.mapping.elements.PageBreakWhiteSpaceElement
import org.brailleblaster.perspectives.braille.mapping.elements.WhiteSpaceElement
import org.brailleblaster.perspectives.braille.messages.Sender
import org.brailleblaster.perspectives.braille.messages.WhitespaceMessage
import org.brailleblaster.perspectives.mvc.XMLTextCaret
import org.brailleblaster.perspectives.mvc.events.XMLCaretEvent
import org.brailleblaster.util.LINE_BREAK
import org.brailleblaster.util.WhitespaceUtils.appendLineBreakElement
import org.brailleblaster.util.WhitespaceUtils.prependLineBreakElement
import org.brailleblaster.util.WhitespaceUtils.removeLineBreakElements

class WhitespaceTransformer(manager: Manager) : Handler(manager, manager.viewInitializer, manager.mapList) {
private var pendingCursorOffset: Int = -1

fun transformWhiteSpace(message: WhitespaceMessage) {
pendingCursorOffset = message.offset
//if(isInline(list.getCurrent()))
// transformInlineText((WhiteSpaceElement)list.get(message.getIndex()), message.getNewText());
//else
Expand Down Expand Up @@ -73,6 +78,33 @@ class WhitespaceTransformer(manager: Manager) : Handler(manager, manager.viewIni
blankLinesBefore-- //An extra line break element is added to the previous tme
}

// When typing within a PageBreakWhiteSpaceElement, the entire blank page area is
// represented by a single maplist entry, so the maplist-index-based blankLinesBefore
// is always 1. Override it with the actual visual distance from the previous text
// element to the cursor so that the correct number of blank lines is inserted before
// the new text.
if (wse is PageBreakWhiteSpaceElement && pendingCursorOffset >= 0 && !atBeginning && curElement != null) {
val view = manager.text.view
// curElement.getEnd(list) is the charCount at the moment curElement finished
// rendering, which equals the widget offset of the '\r' that terminates
// curElement's own line. getLineAtOffset() of that position returns
// curElement's line number.
//
// The number of NEW_LINE elements needed to place text at the cursor's visual
// line is exactly (cursorLine - curElementLine), so we use curElement.getEnd()
// directly as the reference point rather than curElement.getEnd() + LINE_BREAK
// (which would point to the start of the NEXT line and undercount by 1).
val pbStart = curElement.getEnd(list)
if (view.charCount > 0 && pbStart >= 0 && pbStart < view.charCount) {
val pbStartLine = view.getLineAtOffset(pbStart)
val cursorLine = view.getLineAtOffset(pendingCursorOffset.coerceIn(0, view.charCount - 1))
val visualBlankLines = cursorLine - pbStartLine
if (visualBlankLines > blankLinesBefore) {
blankLinesBefore = visualBlankLines
}
}
}

if (nextElement != null) { //nextElement is null at the end of the document
//Remove all existing line breaks between the two elements
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.brailleblaster.easierxml.ImageUtils.getImageNavigateBlock
import org.brailleblaster.math.mathml.MathModuleUtils
import org.brailleblaster.perspectives.braille.Manager
import org.brailleblaster.perspectives.braille.mapping.elements.BraillePageBrlMapElement
import org.brailleblaster.perspectives.braille.mapping.elements.PageBreakWhiteSpaceElement
import org.brailleblaster.perspectives.braille.mapping.elements.PageIndicator
import org.brailleblaster.perspectives.braille.mapping.maps.MapList
import org.brailleblaster.perspectives.braille.mapping.maps.PaintedElementsList
Expand Down Expand Up @@ -97,6 +98,16 @@ class StylePane(parent: Composite, private val m: Manager) : BBEditorView {
textMapElement.node
)
)
if (textMapElement is PageBreakWhiteSpaceElement) {
val pbEnd = textMapElement.getEnd(mapList)
if (pbEnd >= 0 && pbEnd <= textViewWidget.charCount) {
val pbLine = textViewWidget.getLineAtOffset(pbEnd)
if (!lines.containsKey(pbLine)) {
lines[pbLine] = "Page Break"
}
}
continue
}
if (textMapElement.node == null) {
log.trace("skipping null node")
continue
Expand Down
Loading