Skip to content

Commit

Permalink
Fix bug in Expression SubSup where null and undefined where mixed up
Browse files Browse the repository at this point in the history
  • Loading branch information
HildoBijl committed Jan 25, 2024
1 parent c9c31bb commit e969f81
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
1 change: 0 additions & 1 deletion frontend/src/ui/form/Form/context/hooks/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export function useSubmitCall() {

// Give a submit call function.
return useStableCallback(() => {

// If the input is not valid, do not submit.
if (!isInputValid())
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function mouseClickToCursor(evt, FI, charElements, contentsElement) {
if (trace) {
const cursor = getFIFuncs(FI).charElementClickToCursor(evt, FI, trace, charElements, contentsElement)
// The function may return something falsy, indicating it failed to figure things out. (This may happen when you click on the function name like "log" of a function.) In that case proceed to plan B.
if (cursor !== null)
if (cursor !== null && cursor !== undefined)
return cursor
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function create(expressionFI, part, position, name, alias) {
subSupPart = part - 1
else if (position === element.value.length - 1 && isSubSup(value[part + 1]))
subSupPart = part + 1
if (subSupPart !== undefined) {
if (subSupPart) {
const expressionWithoutAlias = {
...removeCursor(expressionFI),
value: arraySplice(value, part, 1, { ...element, value: element.value.replace(alias, '') }),
Expand Down Expand Up @@ -86,7 +86,7 @@ function moveCursorToSubSup(expressionFI, part, toSubscript, atStart) {
// First check if the respective part (subscript or superscript) still needs to be added.
let element = value[part]
const elementPart = toSubscript ? 0 : 1
if (element.value[elementPart] === undefined) {
if (!element.value[elementPart]) {
element = {
...element,
value: toSubscript ? [getEmptySub(), element.value[1]] : [element.value[0], getEmptySup()]
Expand Down Expand Up @@ -128,11 +128,11 @@ function getInitial(alias) {
if (alias === '_') {
return [
getEmptySub(),
undefined,
null,
]
} else {
return [
undefined,
null,
getEmptySup(),
]
}
Expand Down Expand Up @@ -183,12 +183,12 @@ function cleanUp(FI, settings) {
const { cursor, value } = FI
return {
...FI,
value: value.map((element, part) => element && (!isFIEmpty(element) || (cursor?.part === part)) ? element : undefined),
value: value.map((element, part) => element && (!isFIEmpty(element) || (cursor?.part === part)) ? element : null),
}
}

function canMerge(FI, mergeWithNext, fromOutside) {
return FI.value[1] !== undefined && mergeWithNext // Only merge the superscript with what comes after.
return FI.value[1] && mergeWithNext // Only merge the superscript with what comes after.
}

function merge(FI, partIndex, mergeWithNext, fromOutside) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export function cleanUp(FI, settings) {
const newValue = value.map((_, part) => {
// Extract the element.
const element = zoomInAt(FI, part)
if (element === undefined)
if (!element)
return element

// Clean up the element if we can.
Expand Down
2 changes: 1 addition & 1 deletion shared/CAS/functionalities/Expression/Expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -2026,7 +2026,7 @@ class Fraction extends Function {
}

requiresBracketsFor(level) {
return level === bracketLevels.division || level === bracketLevels.powers || (bracketLevels.multiplication && !this.requiresPlusInSum()) // When divided, in powers, or in multiplication when there's a precursor minus sign, add brackets.
return level === bracketLevels.division || level === bracketLevels.powers || (level === bracketLevels.multiplication && !this.requiresPlusInSum()) // When divided, in powers, or in multiplication when there's a precursor minus sign, add brackets.
}

requiresPlusInSum() {
Expand Down

0 comments on commit e969f81

Please sign in to comment.