import { getSheetForSyncing } from "./getSheetForSyncing" ; import { isHighlightEditedCellsEnabled } from "./isHighlightEditedCellsEnabled" ; import { createHighlightEditedCellsRule } from "./createHighlightEditedCellsRule" ; export function toggleHighlightEditedCells ( ) { const sheet = getSheetForSyncing ( ) ; if ( sheet !== null ) { if ( isHighlightEditedCellsEnabled ( ) === false ) { const rules = sheet . getConditionalFormatRules ( ) ; rules . push ( createHighlightEditedCellsRule ( ) ) ; sheet . setConditionalFormatRules ( rules ) ; return true ; } else { const rules = sheet . getConditionalFormatRules ( ) ; const ruleToRemove = createHighlightEditedCellsRule ( ) ; const newRules = rules . filter ( ( currentRule ) : boolean => { return currentRule . getBooleanCondition ( ) . getCriteriaValues ( ) [ 0 ] !== ruleToRemove . getBooleanCondition ( ) . getCriteriaValues ( ) [ 0 ] ; } ) ; sheet . setConditionalFormatRules ( newRules ) ; return false ; } } else { throw new Error ( "Document has not yet set up for syncing." ) ; } }