/// <inheritdoc /> public override bool Activate(DocumentSelection cursor, CaretMovementMode movementMode, SelectionMode mode) { // first we try to move the cursor directly var caret = cursor.Start; var next = caret.MoveForward(); // try a simply to move the cursor forwards if (next.IsValid) { cursor.MoveTo(next, mode); return(true); } // try get the block backward to get a cursor that looks at the beginning of that block var block = caret.Block?.Parent.GetBlockTo(BlockDirection.Forward, caret.Block) as ContentBlock; if (block != null) { cursor.MoveTo(block.GetCaretAtStart(), mode); return(true); } // we couldn't do it return(false); }
/// <inheritdoc /> public override bool Activate(DocumentSelection cursor, CaretMovementMode movementMode, SelectionMode mode) { var textCaret = cursor.Start.As <TextCaret>(); double desiredPosition = UpdateMovementMode(movementMode, textCaret); var contentView = textCaret.Block.GetViewOrNull <ITextBlockView>(); if (contentView == null) { return(false); } var currentLine = contentView.GetLineFor(textCaret); var nextLine = currentLine.Next; if (nextLine != null) { // TODO what if it's invalid (maybe only if the line couldn't be found?) var caret = nextLine.FindClosestTo(desiredPosition); if (!caret.IsValid) { return(false); } cursor.MoveTo(caret, mode); return(true); } var currentBlock = textCaret.Block; var nextBlock = currentBlock.Parent.GetBlockTo(BlockDirection.Bottom, currentBlock); if (nextBlock != null) { if (nextBlock.GetViewOrNull <IBlockView>() is IBlockView nextBlockView) { var newCursor = nextBlockView.GetCaretFromTop(movementMode); cursor.MoveTo(newCursor, mode); return(true); } else { return(false); } } // TODO work the way up the document // we couldn't do it return(false); }
/// <inheritdoc/> public override bool Activate(DocumentSelection cursor, CaretMovementMode movementMode, SelectionMode mode) { var textCaret = cursor.Start.As <TextCaret>(); movementMode.SetModeToHome(); var contentView = textCaret.Block.GetViewOrNull <ITextBlockView>(); if (contentView == null) { return(false); } textCaret = contentView.GetLineFor(textCaret).FindClosestTo(0); cursor.MoveTo(textCaret, mode); return(true); }