I'm not sure this is the correct way to address the issue. I think we should take the folds into account and perform the motion commands on top of the visible lines instead of the document lines. I tried to replace this PR with
https://github.com/geany/geany-plugins/pull/1338
Please let me know what you think about the changes.