Skip to content

Commit

Permalink
Fix regression: wrong board coordinates on click after scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
pol-rivero committed May 3, 2023
1 parent 3ec223e commit 797f85b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/ChessBoard/internal/ChessgroundAdapter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<script setup lang="ts">
import { Chessground } from 'chessgroundx'
import { chessboardSvg } from './chessboard-svg'
import { clone, throttle } from '@/utils/ts-utils'
import { onMounted, ref } from 'vue'
import { clone, debounce, throttle } from '@/utils/ts-utils'
import { onBeforeUnmount, onMounted, ref } from 'vue'
import type * as cg from 'chessgroundx/types'
import type { Api } from 'chessgroundx/api'
import type { Config } from 'chessgroundx/config'
Expand Down Expand Up @@ -140,6 +140,12 @@
}
}

// Refresh the board when scrolling, so that the click events have the correct coordinates
if (!props.disableRefresh) {
const redrawBoardDebounced = debounce(() => chessgroundApi?.redrawAll())
window.addEventListener('scroll', redrawBoardDebounced)
onBeforeUnmount(() => window.removeEventListener('scroll', redrawBoardDebounced))
}
</script>


Expand Down
1 change: 1 addition & 0 deletions src/components/Variant/Search/SearchCardPlaceholder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
:view-only="true"
:show-coordinates="false"
:capture-wheel-events="false"
:disable-refresh="true"
/>
<p class="mt-3 is-size-5 has-text-weight-semibold">
<HighlightWords
Expand Down
1 change: 1 addition & 0 deletions src/pages/Variant/VariantDetailsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
:view-only="true"
:show-coordinates="true"
:capture-wheel-events="false"
:disable-refresh="true"
/>
</div>
</div>
Expand Down

0 comments on commit 797f85b

Please sign in to comment.