Skip to content

Commit

Permalink
fix: simplify reading mode state
Browse files Browse the repository at this point in the history
The Kwic component had two flags for tracking reading mode, and they would be out of sync if the main Kwic had it enabled when a new KwicTab was created
  • Loading branch information
arildm committed Sep 3, 2024
1 parent e10d74d commit 839df5b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
16 changes: 7 additions & 9 deletions app/scripts/components/kwic.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ angular.module("korpApp").component("kwic", {
hits-per-page="$ctrl.hitsPerPage"
></kwic-pager>
<span ng-if="$ctrl.hits" class="reading_btn link" ng-click="$ctrl.toggleReading()">
<span ng-if="!$ctrl.readingMode">{{'show_reading' | loc:$root.lang}}</span>
<span ng-if="$ctrl.readingMode">{{'show_kwic' | loc:$root.lang}}</span>
<span ng-if="!$ctrl.isReading">{{'show_reading' | loc:$root.lang}}</span>
<span ng-if="$ctrl.isReading">{{'show_kwic' | loc:$root.lang}}</span>
</span>
<div class="table_scrollarea">
<table class="results_table kwic" ng-if="!$ctrl.useContext" cellspacing="0">
Expand Down Expand Up @@ -257,12 +257,10 @@ angular.module("korpApp").component("kwic", {
$ctrl._settings = settings

$ctrl.toggleReading = () => {
$ctrl.readingMode = !$ctrl.readingMode
// Emit event; parent should update isReading
$ctrl.contextChangeEvent()
}

$ctrl.readingMode = $location.search().reading_mode

$ctrl.download = {
options: [
{ value: "", label: "download_kwic" },
Expand Down Expand Up @@ -655,7 +653,7 @@ angular.module("korpApp").component("kwic", {

function selectNext() {
let next
if (!$ctrl.readingMode) {
if (!$ctrl.isReading) {
const i = getCurrentRow().index($element.find(".token_selected").get(0))
next = getCurrentRow().get(i + 1)
if (next == null) {
Expand All @@ -670,7 +668,7 @@ angular.module("korpApp").component("kwic", {

function selectPrev() {
let prev
if (!$ctrl.readingMode) {
if (!$ctrl.isReading) {
const i = getCurrentRow().index($element.find(".token_selected").get(0))
if (i === 0) {
return
Expand All @@ -686,7 +684,7 @@ angular.module("korpApp").component("kwic", {
function selectUp() {
let prevMatch
const current = selectionManager.selected
if (!$ctrl.readingMode) {
if (!$ctrl.isReading) {
prevMatch = getWordAt(
current.offset().left + current.width() / 2,
current.closest("tr").prevAll(":not(.corpus_info)").first()
Expand Down Expand Up @@ -715,7 +713,7 @@ angular.module("korpApp").component("kwic", {
function selectDown() {
let nextMatch
const current = selectionManager.selected
if (!$ctrl.readingMode) {
if (!$ctrl.isReading) {
nextMatch = getWordAt(
current.offset().left + current.width() / 2,
current.closest("tr").nextAll(":not(.corpus_info)").first()
Expand Down
6 changes: 1 addition & 5 deletions app/scripts/controllers/kwic_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,7 @@ export class KwicCtrl implements IController {
s.reading_mode = $location.search().reading_mode
s.toggleReading = function () {
s.reading_mode = !s.reading_mode
if (s.reading_mode) {
$location.search("reading_mode", true)
} else {
$location.search("reading_mode", undefined)
}
$location.search("reading_mode", s.reading_mode || undefined)
s.readingChange()
}

Expand Down

0 comments on commit 839df5b

Please sign in to comment.