Skip to content

Commit

Permalink
Clear query parameters if there are no non-default constraints.
Browse files Browse the repository at this point in the history
This avoid the URL changing when we first reach the page.
  • Loading branch information
sigh committed Sep 3, 2024
1 parent 6961561 commit d55c10d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="description" content="Fast interactive Sudoku solver. Supports many variants including 16x16 grids.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="{{ 'img/favicon.png' | relative_url }}">
<link rel="canonical" href="https://sigh.github.io/Interactive-Sudoku-Solver" />
<link rel="canonical" href="https://sigh.github.io/Interactive-Sudoku-Solver/" />

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-2SQH4BL89R"></script>
Expand Down
16 changes: 8 additions & 8 deletions js/solution_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ class HistoryHandler {
}

_incrementHistory(delta) {
const index = this._historyLocation + delta;
if (index >= this._history.length) return;
let q = this._history[this._historyLocation + delta];
if (q === undefined) return;
this._historyLocation += delta;
this._updateButtons();

Expand Down Expand Up @@ -1233,13 +1234,11 @@ class SolutionController {
this._stateDisplay = new SolverStateDisplay(this._solutionDisplay);

this._historyHandler = new HistoryHandler((params) => {
let mode = params.get('mode');
const mode = params.get('mode');
if (mode) this._elements.mode.value = mode;

let constraintsText = params.get('q');
if (constraintsText) {
this._constraintManager.loadUnsafeFromText(constraintsText);
}
const constraintsText = params.get('q') || '.';
this._constraintManager.loadUnsafeFromText(constraintsText);
});

this._update();
Expand Down Expand Up @@ -1366,9 +1365,10 @@ class SolutionController {

const constraints = this._constraintManager.getConstraints();

let params = { mode: mode, q: constraints };
let params = { mode: mode, q: constraints.toString() };
// Remove mode if it is the default.
if (mode == 'all-possibilities') params.mode = undefined;
if (mode === 'all-possibilities') params.mode = undefined;
if (params.q === '.') params.q = undefined;
this._historyHandler.update(params);

const isLayoutMode = mode === 'validate-layout';
Expand Down

0 comments on commit d55c10d

Please sign in to comment.