Skip to content

Commit

Permalink
feat: added variables for disabling animation globally and per buffer
Browse files Browse the repository at this point in the history
Closes #54
  • Loading branch information
declancm committed Jul 13, 2024
1 parent e792d8b commit 267f957
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
48 changes: 32 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ customizable Neovim plugin written in Lua!

## ✨ Features

* Can add smooth scrolling to any normal mode movement, command, or Lua function
* Can add smooth cursor and window scroll animation to any normal mode movement, command, or Lua function
* Horizontal, vertical, and diagonal scrolling
* Adjusts scroll speed based on movement distance
* Non-blocking delays using luv
* Two scrolling modes:
* `cursor`: Smoothly scrolls the cursor for any movement
* `window`: Smoothly scrolls the window ONLY when the cursor moves out of view
* `cursor`: animate cursor and window scrolling for any movement
* `window`: animate window scrolling ONLY when the cursor moves out of view

## 📋 Requirements

Expand Down Expand Up @@ -71,24 +71,24 @@ return {
-- Delay between each movement step (in ms)
delay = 5,
step_size = {
-- Default number of cursor/window lines moved per step
-- Number of cursor/window lines moved per step
vertical = 1,
-- Default number of cursor/window columns moved per step
-- Number of cursor/window columns moved per step
horizontal = 2,
},
max_delta = {
-- Maximum distance for line movements before smooth
-- scrolling is skipped. Set to `false` to disable
-- Maximum distance for line movements before scroll
-- animation is skipped. Set to `false` to disable
line = false,
-- Maximum distance for column movements before smooth
-- scrolling is skipped. Set to `false` to disable
-- Maximum distance for column movements before scroll
-- animation is skipped. Set to `false` to disable
column = false,
-- Maximum duration for a movement (in ms). Automatically scales the delay and step size
time = 1000,
},
-- The scrolling mode
-- `cursor`: Smoothly scrolls the cursor for any movement
-- `window`: Smoothly scrolls the window ONLY when the cursor moves out of view
-- `cursor`: animate cursor and window scrolling for any movement
-- `window`: animate window scrolling ONLY when the cursor moves out of view
mode = "cursor",
},
}
Expand All @@ -112,7 +112,7 @@ require("cinnamon").setup {

### Basic Keymaps

**Smooth scrolling for ...**
**Scroll animation for ...**

| Category | Keys |
|-|-|
Expand All @@ -124,7 +124,7 @@ require("cinnamon").setup {

### Extra Keymaps

**Smooth scrolling for ...**
**Scroll animation for ...**

| Category | Keys |
|-|-|
Expand All @@ -142,6 +142,8 @@ require("cinnamon").setup {

`require("cinnamon").scroll({command}, {options})`

Executes the given command with cursor and window scroll animation.

* `{command}` __(string|function)__ Can be any of the following:
* Normal mode movement command

Expand Down Expand Up @@ -175,7 +177,6 @@ See the [Default Options](#default-options) for more information.
```lua
local cinnamon = require("cinnamon")

-- Setup the plugin with default options
cinnamon.setup()

-- Centered scrolling:
Expand Down Expand Up @@ -204,5 +205,20 @@ flash.setup({

- `CinnamonCmdPre` - Triggered before the given command is executed
- `CinnamonCmdPost` - Triggered after the given command is executed
- `CinnamonScrollPre` - Triggered before the smooth scroll movement
- `CinnamonScrollPost` - Triggered after the smooth scroll movement
- `CinnamonScrollPre` - Triggered before the scroll animation
- `CinnamonScrollPost` - Triggered after the scroll animation

## 🚫 Disabling

- `vim.b.cinnamon_disable` __(boolean)__ Disable scroll animation for the current buffer
- `vim.g.cinnamon_disable` __(boolean)__ Disable scroll animation globally

Example Usage:

```lua
-- Disable scrolling for help buffers
vim.api.nvim_create_autocmd("FileType", {
pattern = "help",
callback = function() vim.b.cinnamon_disable = true end,
})
```
2 changes: 2 additions & 0 deletions lua/cinnamon/scroll.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ H.scroller = {

local is_scrollable = (
not config.disabled
and not vim.g.cinnamon_disable
and not vim.b.cinnamon_disable
and vim.fn.reg_executing() == "" -- A macro is not being executed
and original_buffer_id == self.buffer_id
and original_window_id == self.window_id
Expand Down

0 comments on commit 267f957

Please sign in to comment.