SlickGrid icon indicating copy to clipboard operation
SlickGrid copied to clipboard

feat: Add Hybrid Selection Model and Drag-Replace

Open 6pac opened this issue 11 months ago • 2 comments

New HybridSelectionModel combines cell and row selection models. It functions like CellSelectionModel except when certain conditions switch it into RowSelectionModel. If the options.rowSelectOverride function exists, then HybridSelectionModel calls it expecting a boolean return to determine whether to behave like RowSelectionModel. If this option is not set, then selection of a column that is a member of the array options.rowSelectColumnObjectArr will be treated with the behaviour of RowSelectionModel.

Drag and Replace option mirrors Excel as closely as possible. When a range of cells is selected, a grey box appears at the bottom right of the selection area, and dragging that grey box expands the selection area and replaces the newly selected cells will the contents of the existing cells. Excel specifically only allows expansion horizontally or vertically, but here we allow both. The current behaviour may be modified.
Note that the spreadsheet example the FormulaEditor causes problems with this new feature because it creates a new CellRangeSelector each time a cell is edited. This editor needs to add an event to the existing grid's CellRangeSelector, or create a new one.

6pac avatar Dec 20 '24 05:12 6pac

That's interesting, it was asked couple times in my repos on how to do that, so this would surely help a lot. Would you be able to provide an animated gif of this in action (I use ShareX app for that)? I also assume this is not ready yet since I see a few console logs in the code. This remind this issue was brought up in my repo and someone came up with this hybrid approach to toggle between the model depending on the use case, see https://stackoverflow.com/a/76810071/1212166

I also renamed the PR to follow Conventional Commit so that it will be auto-detected in the changelog

I also wonder if this new slick.hybridselectionmodel.ts could eventually replace both previous models? That would probably be a breaking change (major version) but even then it's probably a good idea to keep in mind.

ghiscoding avatar Dec 20 '24 18:12 ghiscoding

@ghiscoding this was actually requested by a client. I'm asking them for an example - the HybridSelectionModel is untested at this point. I'll add gifs for both once I get this.

Correct about it not being finished - the console logs are 100% necessary for any debugging of keyboard or mouse input responses. I will remove them once the client, and you, are happy.

6pac avatar Dec 22 '24 21:12 6pac

@6pac there's conflict in the PR mostly because you included the dist/ folder and there was a few changes since you're opened the PR. However, it's preferable to always exclude the dist folder when creating a PR because that will always show conflicts that are hard to merge, but I'm not sure how to exclude folder after the fact. Maybe this SO answer might work

https://stackoverflow.com/a/6618678/1212166

just replace bin with dist, so probably this git command: git rm -r --cached dist/ to exclude dist folder and then push the new commit and always make sure to exclude that folder in the future because yeah it will often show hard to resolve conflicts

ghiscoding avatar Jul 10 '25 21:07 ghiscoding

I was trying to squash merge my commits, but I had had to pull at various points before I could push, so I also had about 30 mainenance commits from the main branch. I tried a rebase twice. While I carefully exclude dist, the first time I still had VS Code open and had forgotten to close the terminal, so it rebuilt dist as the merge was in progress. Not good!
I backed it all out and recovered from backup, and tried again but there are certain conflicts that just won't resolve. My Git knowledge is not good enough at this point, so I've declared it a dumpster fire and will create a new branch and apply each of the feature changes fully and logically.

Might take a week or so to get to that though.

6pac avatar Jul 11 '25 00:07 6pac

yeah including the dist folder is not typically included in any project but because of our SlickGrid history, we kinda have to include it because otherwise the examples won't work either... so anyway, I still think that running the git command I mentioned above should be enough whenever you're nearing the end. Have fun

ghiscoding avatar Jul 11 '25 00:07 ghiscoding

normally I run a checkout dist before any commit, so as to restore everything back to its original state. I wasn't aware of committing anything to dist, that must have happened by accident during a pull back from the main repo.
I'd actually prefer not to pull changes from master to my branch (would rather deal with any changes right at the end), but it doesn't seem possible to push to GitHub sometimes, even just to my branch, without doing so.

6pac avatar Jul 11 '25 00:07 6pac

ahh it might have been me when I tried to merge the changes after the super huge refactoring of the entire SlickGrid core file that moved all functions up and down.

ghiscoding avatar Jul 11 '25 01:07 ghiscoding