Open carlbordum opened 7 years ago
Currently I just let tkinter do whatever it wants with this. I'll probably fix this tomorrow.
What kind of cursor movement would you like? When you go near the bottom should it scroll down line by line or half a page or so at a time? I checked how different editors do this. Vim and Geany work like porcupine works now, nano and emacs scroll down half a page at a time.
When you press enter: create new line if cursor is at one of the four last lines, also scroll one line
So far I haven't seen any other editors actually do this. Can you name one? If you haven't it's OK and porcupine can still do this.
My own setup (Vim) does this. Am not sure where the option is, though.
Vim didn't do that to me with default settings. I'll implement this some day :)
What do you think?
import functools
import tkinter as tk
import tkinter.font as tkfont
class Zaab1tText(tk.Text):
# see() is supposed to scroll the widget so that the index is
# visible, so it makes sense to override it for this
@functools.wraps(tk.Text.see)
def see(self, index):
# do whatever tkinter does by default
super().see(index)
# self['height'] is wrong if the widget has been stretched or
# squeezed by pack or grid
font = tkfont.Font(name=self['font'], exists=True)
rowcount = self.winfo_height() // font.metrics('linespace')
# make sure that we can also see n lines on either side, usually
# n is 5 but it's smaller if the text widget is too big for 5
space_on_each_side = (rowcount-1) // 2 # -1 is the current row
n = min(space_on_each_side, 5)
super().see('%s + %d lines' % (index, n))
super().see('%s - %d lines' % (index, n))
if __name__ == '__main__':
root = tk.Tk()
text = Zaab1tText(root)
text.pack(fill='both', expand=True) # make it stretchable
text.bind('<Return>', (lambda event: text.after_idle(text.see, 'insert')))
with open(__file__, 'r') as f:
text.insert('1.0', f.read())
root.mainloop()
This code doesn't require porcupine in any way. Just run it in a python with tkinter installed.
Tkinter doesn't seem to support scrolling down further than the bottom of the file, so the only possible workaround is to add a bunch of fake newlines at the end of the text widget and scroll down with these. I'd be happy to proved wrong though. Sorry :(
Damn, I still think this would be nice. You can go to the bottom of a document in vim and press zz
to kind of see what I mean.
I just did that, and it did what I expected it to do... Even though I can't do this at the end of the file, would you like to keep a distance between the cursor and the bottom of the view elsewhere? That's doable if there are lines to go between the cursor and the bottom of the text widget.
@Zaab1t can you try the latest master? I added some magic to fix this and I think it's definitely a lot better than before. You'll see it if you navigate up and down with arrow keys in the middle of a long file.
<Zaab1t> this si nice
<Akuli> go to the very end of the file
<Akuli> you'll notice that it doesn't scroll past the end
<Akuli> does that matter so much that i can't close ur github issue?
<Zaab1t> I like this
<Zaab1t> I haven't seen an editor with this feature
<Zaab1t> I still feel like typing at the end would be better WITH this
<Zaab1t> great work!
<Akuli> thanks :)
reopening because i have an idea for making it scroll past the end: add bottom margin to text widget (if possible)
related to #37
The cursor should be kept 4 or 5 lines above the bottom imo