Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] NYT-style fills (Experimental) #41

Open
mizlan opened this issue Feb 28, 2022 · 2 comments
Open

[Feature] NYT-style fills (Experimental) #41

mizlan opened this issue Feb 28, 2022 · 2 comments

Comments

@mizlan
Copy link

mizlan commented Feb 28, 2022

The following patch accounts for the differences in the use of the Backspace key and the behavior when an alphanumeric key is pressed. I've labeled this as experimental but in my testing, I did not find anything wrong with it. I'm very pleasantly surprised at how easy this was, using the numerous helper functions you've defined :)

diff --git a/cursewords/cursewords.py b/cursewords/cursewords.py
index 7c48fd8..e2c287d 100755
--- a/cursewords/cursewords.py
+++ b/cursewords/cursewords.py
@@ -1054,26 +1054,42 @@ def main():
 
             # Letter entry
             elif not puzzle_complete and keypress.isalnum():
-                if not current_cell.is_blankish:
-                    overwrite_mode = True
-                current_cell.entry = keypress.upper()
 
                 if current_cell.marked_wrong:
                     current_cell.marked_wrong = False
                     current_cell.corrected = True
                 modified_since_save = True
-                cursor.advance_within_word(overwrite_mode, wrap_mode=True)
+
+                if current_cell.is_blankish:
+                    cursor.advance_within_word(overwrite_mode=False, wrap_mode=True)
+                else:
+                    is_last_letter = cursor.current_word()[-1] == cursor.position
+
+                    if is_last_letter:
+                        # jump to first blank in current word or next word
+                        cursor.advance_within_word(wrap_mode=True)
+                    else:
+                        # "overwrite" the word
+                        cursor.advance_within_word(overwrite_mode=True, wrap_mode=False)
+
+                # (the old cell)
+                current_cell.entry = keypress.upper()
 
             # Deletion keys
             elif (not puzzle_complete and
                   keypress.name in ['KEY_BACKSPACE', 'KEY_DELETE']):
-                current_cell.clear()
-                overwrite_mode = True
                 modified_since_save = True
-                if keypress.name == 'KEY_BACKSPACE':
-                    cursor.retreat_within_word(end_placement=True)
-                elif keypress.name == 'KEY_DELETE':
-                    cursor.advance_within_word(overwrite_mode=True)
+
+                # just delete current cell, do not move
+                if not current_cell.is_blankish:
+                    current_cell.clear()
+                else:
+                    # delete *after* you move
+                    if keypress.name == 'KEY_BACKSPACE':
+                        cursor.retreat_within_word(end_placement=True)
+                    elif keypress.name == 'KEY_DELETE':
+                        cursor.advance_within_word(overwrite_mode=True)
+                    grid.cells.get(cursor.position).clear()
 
             # Navigation
             elif (keypress.name in ['KEY_TAB'] or
@mizlan
Copy link
Author

mizlan commented Feb 28, 2022

You'd probably want to figure out a configuration system before I make a PR. If you're okay with it, I can also go ahead and make a PR with an --nyt-fill flag that would enable these controls.

@mizlan
Copy link
Author

mizlan commented Feb 28, 2022

Oops some flags in function arguments are default values and are hence redundant. Will fix later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant