se-edu/addressbook-level3

Space character dropped at line break when converting to PDF

damithc opened this issue · 3 comments

When converting the UG to PDF format, the space character at a line break can be lost e.g.,

image

This affects users copy-pasting commands from the UG to the app.

Hmm, after some investigation, I am not sure if it is a browser specific issue, when a line is wrapped, an additional space is inserted at the wrapped position whether or not there was a space before.

image
Copied text: add n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01- 01

image
Copied text: add n/Betsy Crowe t/friend e/betsycrowe@example.com a/Newgate Prison p/1234567 t/criminal

It seems wrapped text is being replaced by some form of line break character which causes it to be ignored when pasting directly into AB3.

However, as wrapping can occur on dashes like in the example above, it can still affect copy-pasting commands

Right now, I have some ideas regarding fixing the 2 issues above (text wrapping on non-white space characters like dash and linebreaks being ignored when pasting into textfield).


Regarding text wrapping on non-whitespace characters,
a possible solution is to include a javascript that automatically replaces the characters with a nonbreak version for instance, replacing (-) with a non-break version (U+02011), which will prevent linewrap on dashes.
However,

  • if students uses dash in their tp, it might lead to failure to run command when copied since it is now a different character.
  • Commands like java -jar XXX might fail since java will not recognize no break dashes

Regarding pasting into AB3, it is possible to replace linebreaks like characters with space via code.

The way to do this is to subclass JavaFX's TextField class and override the paste method.
Like so

package seedu.address.ui;

import javafx.scene.control.TextField;
import javafx.scene.input.Clipboard;

public class ModifiedTextField extends TextField {

    @Override
    public void paste() {
        // Intercept the paste operation
        String modifiedContent = Clipboard.getSystemClipboard().getString().replaceAll("\n", " ");
        replaceSelection(modifiedContent);
    }
}

import it in the FXML and then replacing the <TextField ... with <ModifiedTextField ....

However, doing so will cause issue where the fxml file can no longer be opened in SceneBuilder as it does not support custom JavaFX classes.


@damithc
I have privately tested both solutions and verified that they work but I am not sure if the benefits this bring outweighs the downsides of the solutions.

I have privately tested both solutions and verified that they work but I am not sure if the benefits this bring outweighs the downsides of the solutions.

Yes, I think the solutions may be not worth the effort. Perhaps we can add a caution about this in the UG instead.