@@ -84,17 +84,17 @@ class StyledTextAreaBehavior {
8484 consume (
8585 anyOf (keyPressed (DOWN ), keyPressed (KP_DOWN )),
8686 (b , e ) -> b .nextLine (SelectionPolicy .CLEAR )),
87- consume (keyPressed (PAGE_UP ), (b , e ) -> b .prevPage (SelectionPolicy .CLEAR )),
88- consume (keyPressed (PAGE_DOWN ), (b , e ) -> b .nextPage (SelectionPolicy .CLEAR )),
87+ consume (keyPressed (PAGE_UP ), (b , e ) -> b .view . prevPage (SelectionPolicy .CLEAR )),
88+ consume (keyPressed (PAGE_DOWN ), (b , e ) -> b .view . nextPage (SelectionPolicy .CLEAR )),
8989 // vertical selection
9090 consume (
9191 anyOf (keyPressed (UP , SHIFT_DOWN ), keyPressed (KP_UP , SHIFT_DOWN )),
9292 (b , e ) -> b .prevLine (SelectionPolicy .ADJUST )),
9393 consume (
9494 anyOf (keyPressed (DOWN , SHIFT_DOWN ), keyPressed (KP_DOWN , SHIFT_DOWN )),
9595 (b , e ) -> b .nextLine (SelectionPolicy .ADJUST )),
96- consume (keyPressed (PAGE_UP , SHIFT_DOWN ), (b , e ) -> b .prevPage (SelectionPolicy .ADJUST )),
97- consume (keyPressed (PAGE_DOWN , SHIFT_DOWN ), (b , e ) -> b .nextPage (SelectionPolicy .ADJUST ))
96+ consume (keyPressed (PAGE_UP , SHIFT_DOWN ), (b , e ) -> b .view . prevPage (SelectionPolicy .ADJUST )),
97+ consume (keyPressed (PAGE_DOWN , SHIFT_DOWN ), (b , e ) -> b .view . nextPage (SelectionPolicy .ADJUST ))
9898 );
9999
100100 InputMapTemplate <StyledTextAreaBehavior , KeyEvent > otherNavigation = sequence (
@@ -165,7 +165,7 @@ class StyledTextAreaBehavior {
165165 InputMapTemplate <StyledTextAreaBehavior , KeyEvent > charPressConsumer = consume (keyPressed ().onlyIf (isChar .and (noControlKeys )));
166166
167167 InputMapTemplate <StyledTextAreaBehavior , ? super KeyEvent > keyPressedTemplate = edits
168- .orElse (otherNavigation ).ifConsumed ((b , e ) -> b .clearTargetCaretOffset ())
168+ .orElse (otherNavigation ).ifConsumed ((b , e ) -> b .view . clearTargetCaretOffset ())
169169 .orElse (verticalNavigation )
170170 .orElse (copyAction )
171171 .orElse (charPressConsumer );
@@ -214,19 +214,6 @@ private enum DragState {
214214 */
215215 private DragState dragSelection = DragState .NO_DRAG ;
216216
217- /**
218- * Remembers horizontal position when traversing up / down.
219- */
220- private Optional <CaretOffsetX > targetCaretOffset = Optional .empty ();
221- private void clearTargetCaretOffset () {
222- targetCaretOffset = Optional .empty ();
223- }
224- private CaretOffsetX getTargetCaretOffset () {
225- if (!targetCaretOffset .isPresent ())
226- targetCaretOffset = Optional .of (view .getCaretOffsetX ());
227- return targetCaretOffset .get ();
228- }
229-
230217 private final Var <Point2D > autoscrollTo = Var .newSimpleVar (null );
231218
232219 /* ********************************************************************** *
@@ -359,7 +346,7 @@ private void downLines(SelectionPolicy selectionPolicy, int nLines) {
359346 Position targetLine = currentLine .offsetBy (nLines , Forward ).clamp ();
360347 if (!currentLine .sameAs (targetLine )) {
361348 // compute new caret position
362- CharacterHit hit = view .hit (getTargetCaretOffset (), targetLine );
349+ CharacterHit hit = view .hit (view . getTargetCaretOffset (), targetLine );
363350
364351 // update model
365352 model .moveTo (hit .getInsertionIndex (), selectionPolicy );
@@ -374,19 +361,6 @@ private void nextLine(SelectionPolicy selectionPolicy) {
374361 downLines (selectionPolicy , 1 );
375362 }
376363
377- private void prevPage (SelectionPolicy selectionPolicy ) {
378- view .showCaretAtBottom ();
379- CharacterHit hit = view .hit (getTargetCaretOffset (), 1.0 );
380- model .moveTo (hit .getInsertionIndex (), selectionPolicy );
381- }
382-
383- private void nextPage (SelectionPolicy selectionPolicy ) {
384- view .showCaretAtTop ();
385- CharacterHit hit = view .hit (getTargetCaretOffset (), view .getViewportHeight () - 1.0 );
386- model .moveTo (hit .getInsertionIndex (), selectionPolicy );
387- }
388-
389-
390364 /* ********************************************************************** *
391365 * Mouse handling implementation *
392366 * ********************************************************************** */
@@ -423,7 +397,7 @@ private void mousePressed(MouseEvent e) {
423397 }
424398
425399 private void firstLeftPress (CharacterHit hit ) {
426- clearTargetCaretOffset ();
400+ view . clearTargetCaretOffset ();
427401 IndexRange selection = model .getSelection ();
428402 if (view .isEditable () &&
429403 selection .getLength () != 0 &&
0 commit comments