raw-bacon / vi-xournalpp

A small plugin for Xournal++ version 1.1.x and 1.2.x with vi-like modes
38 stars 4 forks source link

Missing Keybindings #17

Open raw-bacon opened 2 years ago

raw-bacon commented 2 years ago
BertrandSim commented 3 weeks ago

Hello, I'm a user of your plugin. For toggle snapping, I have the following:

function clickGridSnap(enabled)
  app.uiAction({
    ["action"] = "ACTION_GRID_SNAPPING", 
    ["group"] = "GROUP_GRID_SNAPPING", 
    ["enabled"] = enabled
  })
end

in api.lua, and

  GridSnap = {
    description = "Grid Snapping",
    buttons     = {"g"},
    modes       = {"visual", "shape"},
    call        = clickGridSnap
  },

  GridSnapOff = {
    description = "Grid Snapping Disable",
    buttons     = {"<Shift>g"},
    modes       = {"visual", "shape"},
    call        = function() clickGridSnap(false) end
  },

in keybindings.lua.

The intention was for 'ag' and 'aG' to enable/disable grid snapping respectively.

However, I found that both 'ag' and 'aG' toggles the grid snapping, rather than turning them on or off.

I've tried to find a fix, such as removing the "group" argument in clickGridSnap, but to no avail. Do you have any idea?

Rapha149 commented 2 weeks ago

Hello, I'm a user of your plugin. For toggle snapping, I have the following:

function clickGridSnap(enabled)
  app.uiAction({
    ["action"] = "ACTION_GRID_SNAPPING", 
    ["group"] = "GROUP_GRID_SNAPPING", 
    ["enabled"] = enabled
  })
end

in api.lua, and

  GridSnap = {
    description = "Grid Snapping",
    buttons     = {"g"},
    modes       = {"visual", "shape"},
    call        = clickGridSnap
  },

  GridSnapOff = {
    description = "Grid Snapping Disable",
    buttons     = {"<Shift>g"},
    modes       = {"visual", "shape"},
    call        = function() clickGridSnap(false) end
  },

in keybindings.lua.

The intention was for 'ag' and 'aG' to enable/disable grid snapping respectively.

However, I found that both 'ag' and 'aG' toggles the grid snapping, rather than turning them on or off.

I've tried to find a fix, such as removing the "group" argument in clickGridSnap, but to no avail. Do you have any idea?

That's because in the current version of Xournal++ the action ACTION_GRID_SNAPPING toggles the grid snapping, as can be seen in Control.cpp#L910. However, since the last release, this behaviour has changed. As you can see in ActionProperties.h#L237 in the currently newest version on Github, it now uses the enabled flag (it's a different class now because the whole action system got restructured). Therefore, if you install the nightly release or install the unstable versions from your package manager if possible (e.g. the Unstable PPA for Ubuntu) or compile Xournal++ yourself, you can then use your api snippet to get the on/off and not the toggle behaviour. However, if you do this (as I have done, for other reasons) you will have to rewrite some other parts of the api as well because other things have changed too.

Btw, the group argument is only used for debug purposes right now, it doesn't have any impact on the action, at least to my knowledge.