Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paper tape inserts newline after each entry #955

Closed
SyntaxBlitz opened this issue May 26, 2018 · 5 comments
Closed

Paper tape inserts newline after each entry #955

SyntaxBlitz opened this issue May 26, 2018 · 5 comments
Labels

Comments

@SyntaxBlitz
Copy link

Summary

There is always an unused newline at the bottom of the paper tape dialog. This unused space is particularly troublesome when using a big font and a small output window. This also happens in the suggestions pane.
selection_598

Reproducing

  1. Open the paper tape.
  2. Write enough strokes to fill the window so that it begins to scroll.

Plover Version

Plover 4.0.0.dev6+5.ga564116

System

Ubuntu 16.10 with i3-gaps, running plover-4.0.0.dev6.5.ga564116-x86_64.AppImage

@DanLanglois
Copy link

DanLanglois commented May 31, 2018

I'm thinking of how to implement the change, assuming it is approved..

There is a widget, a QTextEdit, called 'suggestions'. And I see that here, a newline is being added manually:

plover/plover/gui_qt/suggestions_widget.py shows this:
48 cursor.insertText('\n')

So there is always a trailing newline. Therefore, probably move it up a bit to here:
34 cursor.movePosition(QTextCursor.End)
[35 cursor.insertText('\n')]

This way, the newline only gets created when it's about to be 'used'.

That's one, the suggestions pane one, but then there is the paper tape one..

The paper tape one is readOnly. It's a QPlainTextEdit called 'tape'. In this case, the method appendPlainText() adds actually new paragraph. Yet, you need to append text to QPlainTextEdit without adding a newline to the text. Currently there is this:

plover/plover/gui_qt/paper_tape.py
113 def _show_stroke(self, stroke):
114 text = self._formatter(stroke)
115 self.tape.appendPlainText(text)

I think the 'fix' is this kind of approach:
113 def _show_stroke(self, stroke):
114 text = self._formatter(stroke)
[
115 # self.tape is a QPlainTextEdit object
116 self.tape.moveCursor(QTextCursor.End)
117 self.tape.insertPlainText ("\n"+text)
118 self.tape.moveCursor (QTextCursor.End)
]

..I could have attempted a pull request, but I .. could have, I suppose .. I'm kind of at the getting oriented stage.

@SeaLiteral
Copy link

Is this bug still present in the current version of Plover? I can't seem to reproduce it now, but I can get more than two thirds of an empty line below the last stroke depending on the size of the window.

@SeaLiteral
Copy link

Well, right now it seems it is still there. So no, it doesn't seem to have been fixed.

@user202729
Copy link
Member

user202729 commented Oct 22, 2020

This is likely Qt's bug rather than Plover's, as depends on the paper tape size, the size of the last "empty line" varies from (approximately) 2/3 to 5/3 of a line of text. If Qt doesn't have the bug, and there's a trailing new line, the size of it should be from 1 to 2 of a line of text.

However, this can be fixed, although it might break something else.

Method 1:

     def _show_stroke(self, stroke):
         text = self._formatter(stroke)
         self.tape.appendPlainText(text)
 
+        self.tape.moveCursor(QTextCursor.End)
+        self.tape.ensureCursorVisible()
+

Problem: if the user want to view the upper part of the paper tape and stroke something, the tape is scrolled to the bottom; and if the user selects something, it will be cleared.

Method 2:

     def _show_stroke(self, stroke):
+        vertical_scroll_bar = self.tape.verticalScrollBar()
+        old_value = vertical_scroll_bar.value()
+        self.tape.moveCursor(QTextCursor.End)
+        self.tape.ensureCursorVisible()
+        at_end = old_value == vertical_scroll_bar.value()
+        if not at_end:
+            vertical_scroll_bar.setValue(old_value)
+
         text = self._formatter(stroke)
         self.tape.appendPlainText(text)
 
+        if at_end:
+            self.tape.moveCursor(QTextCursor.End)
+            self.tape.ensureCursorVisible()
+

The first issue mentioned above is fixed, but not the second one.

By the way, it looks like that the horizontal scroll bar in paper mode is not wanted (the window is forced to be larger than the text in the first line), but it is still visible in some cases because of the margin of the QPlainTextEdit. setHorizontalScrollBarPolicy can be used.

@benoit-pierre
Copy link
Member

Probably fixed in #1308, with the switch to a list view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants