forked from onivim/oni2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Selection behavior for inputs (onivim#1264)
* Selection behavior for inputs - Adds ability for input to have selected text - Adds handlers for Shift/Control key combination with control keys - Adds test to cover new behavior Removed unused code. Updated to handle <Right> key at the end of selection Update to have better variable names * Update to fit new skia render. Update wild menu to don't have a dropdown. * Added Selection module * Updated InputModel to work with Selection model - Added tests * Attempt to integrate new selection module. * Fixed type issues. * Refactored Selection module in functional way * Added new line at the end of file * Update SCM feature to use new input handler * Formatted the code * Code refactoring - Updates to don't have realative methods for Selection module - Update to have better names - Update to have more DRY code * Better variable names * Better variable names * Update to don't have Selection focus/anchor
- Loading branch information
Showing
20 changed files
with
1,776 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
open Utility; | ||
|
||
[@deriving show({with_path: false})] | ||
type t = { | ||
anchor: int, | ||
focus: int, | ||
}; | ||
|
||
let initial: t = {anchor: 0, focus: 0}; | ||
|
||
let create = (~text: string, ~anchor: int, ~focus: int): t => { | ||
let safeOffset = IntEx.clamp(~lo=0, ~hi=String.length(text)); | ||
|
||
let safeAnchor = safeOffset(anchor); | ||
let safeFocus = safeOffset(focus); | ||
|
||
{anchor: safeAnchor, focus: safeFocus}; | ||
}; | ||
|
||
let length = (selection: t): int => { | ||
abs(selection.focus - selection.anchor); | ||
}; | ||
|
||
let offsetLeft = (selection: t): int => { | ||
min(selection.focus, selection.anchor); | ||
}; | ||
|
||
let offsetRight = (selection: t): int => { | ||
max(selection.focus, selection.anchor); | ||
}; | ||
|
||
let isCollapsed = (selection: t): bool => { | ||
selection.anchor == selection.focus; | ||
}; | ||
|
||
let collapsed = (~text: string, offset: int): t => { | ||
create(~text, ~anchor=offset, ~focus=offset); | ||
}; | ||
|
||
let extend = (~text: string, ~selection: t, offset: int): t => { | ||
create(~text, ~anchor=selection.anchor, ~focus=offset); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[@deriving show({with_path: false})] | ||
type t = | ||
pri { | ||
anchor: int, | ||
focus: int, | ||
}; | ||
|
||
let initial: t; | ||
|
||
let create: (~text: string, ~anchor: int, ~focus: int) => t; | ||
let length: t => int; | ||
let offsetLeft: t => int; | ||
let offsetRight: t => int; | ||
let isCollapsed: t => bool; | ||
|
||
let collapsed: (~text: string, int) => t; | ||
|
||
let extend: (~text: string, ~selection: t, int) => t; |
Oops, something went wrong.