Vertically Centering Cursor in Field *Solved*
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Vertically Centering Cursor in Field
Maybe the typewriter metaphor was a bit confusing. What I'm trying to do is scroll lock the cursor to, more or less, the center of the field--for most of the doc at least. This should create the effect of the paragraphs scrolling up to meet the cursor position. And because it does this, edits, returns, etc., happen more central to the field.
My script does a version of this, At least in my testing. It's a bit herky-jerky but basically functional. But translating the character count to a vScroll percent is a vague measure. Ideally, I think, the scroll would be linked to a percentage of visual (soft wrapped) lines.
My script does a version of this, At least in my testing. It's a bit herky-jerky but basically functional. But translating the character count to a vScroll percent is a vague measure. Ideally, I think, the scroll would be linked to a percentage of visual (soft wrapped) lines.
Re: Vertically Centering Cursor in Field
What if you set a very large bottom margin on the field so that the last visible line of the text is spaced half-way up the height of the field, and then in the field script (without any other code)For me, that seems to do what you want, assuming I have understood what you want!
[edit] I think I have misunderstood, because this applies to having empty space at the end of the field so that a newly typed line is centred vertically. Works great, except that I think you want to be able to scroll up and down within pre-existing text and have the insertion point always at the middle vertically. Right?[/edit]
Code: Select all
on textChanged
set the vScroll of me to the formattedHeight of me
end textChanged
[edit] I think I have misunderstood, because this applies to having empty space at the end of the field so that a newly typed line is centred vertically. Works great, except that I think you want to be able to scroll up and down within pre-existing text and have the insertion point always at the middle vertically. Right?[/edit]
Re: Vertically Centering Cursor in Field
Is Sparkout correct? I had thought you wanted a "typewriter", where the "current" line is always in the same place vertically, and whatever you have already typed lives above.
To hold the cursor at the same vLoc, regardless of how you edit, scroll, cut and paste or otherwise manipulate EXISTING text, including text below, is a different problem.
Craig
To hold the cursor at the same vLoc, regardless of how you edit, scroll, cut and paste or otherwise manipulate EXISTING text, including text below, is a different problem.
Craig
Re: Vertically Centering Cursor in Field
Try this in the field scriptI have "spelt out" the construction of the calculated offset step by step, you can obviously condense this.
Code: Select all
on textChanged
centerCursor
end textChanged
on selectionChanged
centerCursor
end selectionChanged
on centerCursor
put the top of me into tTop
put the height of me / 2 into tYoff
put tTop + tYoff into tYmid
put item 2 of the selectedLoc into tYLoc
put tYmid - tYLoc into tScrollOffset
put the vScroll of me into tVscroll
put tVscroll - tScrollOffset into tNewVScroll
set the vScroll of me to tNewVScroll
end centerCursor
Re: Vertically Centering Cursor in Field
Glad it worked. This is actually an implementation of what jacque suggested in the first reply to your question. 

Re: Vertically Centering Cursor in Field
I rarely use long text fields and mostly don't even use scrolling fields, so selectedLoc and vScroll I don't know much of anything about. So I couldn't make the association that she was trying to point me towards. A made a more complicated one that didn't work as well 

Last edited by monki on Sun Aug 02, 2020 4:00 pm, edited 1 time in total.
Re: Vertically Centering Cursor in Field
Yes, we all do stuff like that. I didn't mean you were at fault, I just didn't want to steal credit from jacque for her suggestion.