Skip to content

Commit

Permalink
Merge branch 'pr/mobile/implement-toolbar-redesign'
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator committed Dec 5, 2024
2 parents 5fefe26 + d110a22 commit f55e312
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,18 @@ const keyExtractor = (item: ToolbarItem, index: number) => {
}
};

const setCommandIncluded = (commandName: string, allCommandNames: string[], include: boolean) => {
const lastSelectedCommands = Setting.value('editor.toolbarButtons');

const setCommandIncluded = (
commandName: string,
lastSelectedCommands: string[],
allCommandNames: string[],
include: boolean,
) => {
let newSelectedCommands;
if (include) {
newSelectedCommands = [];
for (const name of allCommandNames) {
if (name === commandName || lastSelectedCommands.includes(name)) {
const isDivider = name === '-';
if (isDivider || name === commandName || lastSelectedCommands.includes(name)) {
newSelectedCommands.push(name);
}
}
Expand Down Expand Up @@ -104,7 +108,7 @@ const ToolbarEditorScreen: React.FC<Props> = props => {
accessibilityRole='checkbox'
accessibilityState={{ checked }}
aria-checked={checked}
onPress={() => setCommandIncluded(item.name, props.allCommandNames, !checked)}
onPress={() => setCommandIncluded(item.name, props.selectedCommandNames, props.allCommandNames, !checked)}
>
<View style={styles.listItem}>
<Icon name={checked ? 'ionicon checkbox-outline' : 'ionicon square-outline'} style={styles.icon} accessibilityLabel={null}/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AppState } from '../../../utils/types';
import { utils as pluginUtils } from '@joplin/lib/services/plugins/reducer';
import { EditorCommandType } from '@joplin/editor/types';

const defaultCommandNames = [
const builtInCommandNames = [
'attachFile',
'-',
EditorCommandType.ToggleHeading1,
Expand Down Expand Up @@ -33,10 +33,10 @@ const allCommandNamesFromState = (state: AppState) => {
const pluginCommandNames = pluginUtils.commandNamesFromViews(state.pluginService.plugins, 'editorToolbar');

if (pluginCommandNames.length > 0) {
return defaultCommandNames.concat(['-'], pluginCommandNames);
return builtInCommandNames.concat(['-'], pluginCommandNames);
}

return defaultCommandNames;
return builtInCommandNames;
};

export default allCommandNamesFromState;

0 comments on commit f55e312

Please sign in to comment.