-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
139 additions
and
151 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
local Directions = require("gesture.core.directions") | ||
local UP = Directions.UP | ||
local DOWN = Directions.DOWN | ||
local RIGHT = Directions.RIGHT | ||
local LEFT = Directions.LEFT | ||
|
||
local DirectionInput = {} | ||
|
||
function DirectionInput.new(direction, length) | ||
vim.validate({ | ||
direction = { direction, "string" }, | ||
length = { length, "number" }, | ||
}) | ||
return { | ||
direction = direction, | ||
length = length, | ||
} | ||
end | ||
|
||
function DirectionInput.from_points(p1, p2) | ||
local diff_x = p2.x - p1.x | ||
local length_x = math.abs(diff_x) | ||
|
||
local diff_y = p2.y - p1.y | ||
local length_y = math.abs(diff_y) | ||
|
||
local direction, length | ||
if length_x > length_y then | ||
direction = diff_x > 0 and RIGHT or LEFT | ||
length = length_x | ||
elseif length_y >= length_x and length_y > 0 then | ||
direction = diff_y > 0 and DOWN or UP | ||
length = length_y | ||
else | ||
return nil | ||
end | ||
|
||
return DirectionInput.new(direction, length) | ||
end | ||
|
||
function DirectionInput.is_short(input, length_thresholds) | ||
if input.direction == UP or input.direction == DOWN then | ||
return input.length < length_thresholds.y | ||
end | ||
return input.length < length_thresholds.x | ||
end | ||
|
||
return DirectionInput |
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,59 @@ | ||
local DirectionInputDefinition = {} | ||
DirectionInputDefinition.__index = DirectionInputDefinition | ||
|
||
local new = function(value, opts) | ||
vim.validate({ | ||
typ = { value, "string" }, | ||
opts = { opts, "table", true }, | ||
}) | ||
|
||
opts = opts or {} | ||
|
||
vim.validate({ | ||
max_length = { opts.max_length, "number", true }, | ||
min_length = { opts.min_length, "number", true }, | ||
}) | ||
|
||
local tbl = { | ||
value = value, | ||
max_length = opts.max_length, | ||
min_length = opts.min_length, | ||
} | ||
return setmetatable(tbl, DirectionInputDefinition) | ||
end | ||
|
||
local Directions = require("gesture.core.directions") | ||
|
||
function DirectionInputDefinition.up(opts) | ||
return new(Directions.UP, opts) | ||
end | ||
|
||
function DirectionInputDefinition.down(opts) | ||
return new(Directions.DOWN, opts) | ||
end | ||
|
||
function DirectionInputDefinition.right(opts) | ||
return new(Directions.RIGHT, opts) | ||
end | ||
|
||
function DirectionInputDefinition.left(opts) | ||
return new(Directions.LEFT, opts) | ||
end | ||
|
||
function DirectionInputDefinition.equals(self, input_definition) | ||
return self.value == input_definition.value | ||
and self.max_length == input_definition.max_length | ||
and self.min_length == input_definition.min_length | ||
end | ||
|
||
function DirectionInputDefinition.match(self, input) | ||
if self.max_length and self.max_length < input.length then | ||
return false | ||
end | ||
if self.min_length and self.min_length > input.length then | ||
return false | ||
end | ||
return true | ||
end | ||
|
||
return DirectionInputDefinition |
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,6 @@ | ||
return { | ||
UP = "UP", | ||
DOWN = "DOWN", | ||
RIGHT = "RIGHT", | ||
LEFT = "LEFT", | ||
} |
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 was deleted.
Oops, something went wrong.
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