コマンドを実行したときにスクロールされない問題を修正

This commit is contained in:
L7Cy 2023-09-02 12:32:54 +09:00
parent 7666536ddd
commit bba41f4520
2 changed files with 7 additions and 15 deletions

View file

@ -2,23 +2,19 @@ import React from 'react';
import { createRoot } from 'react-dom/client';
import { WorkspaceLeaf, ItemView } from 'obsidian';
import DynamicTimetable from './main';
import TimetableViewComponent, {
TimetableViewComponentRef,
} from './TimetableViewComponent';
import TimetableViewComponent from './TimetableViewComponent';
import { CommandsManager } from './Commands';
export class TimetableView extends ItemView {
private readonly plugin: DynamicTimetable;
private componentRef: React.RefObject<TimetableViewComponentRef>;
private root: any;
private commandsManager: CommandsManager;
constructor(leaf: WorkspaceLeaf, plugin: DynamicTimetable) {
super(leaf);
this.plugin = plugin;
this.componentRef = React.createRef<TimetableViewComponentRef>();
this.commandsManager = new CommandsManager(plugin);
this.icon = "table";
this.icon = 'table';
}
getViewType(): string {
@ -33,7 +29,7 @@ export class TimetableView extends ItemView {
this.root = createRoot(this.containerEl);
this.root.render(
<TimetableViewComponent
ref={this.componentRef}
ref={this.plugin.timetableViewComponentRef}
plugin={this.plugin}
commandsManager={this.commandsManager}
/>
@ -47,8 +43,8 @@ export class TimetableView extends ItemView {
}
async update() {
if (this.componentRef.current) {
this.componentRef.current.update();
if (this.plugin.timetableViewComponentRef.current) {
this.plugin.timetableViewComponentRef.current.update();
}
}
}

View file

@ -12,7 +12,7 @@ import ProgressBar from './ProgressBar';
import { CommandsManager } from './Commands';
import BufferTimeRow from './BufferTimeRow';
import TaskRow from './TaskRow';
import { MarkdownView, Notice } from 'obsidian';
import { Notice } from 'obsidian';
import {
convertHexToHSLA,
getHSLAColorForCategory,
@ -70,10 +70,6 @@ const TimetableViewComponent = forwardRef<
const performScroll = () => {
if (firstUncompletedTaskRef.current && containerRef.current) {
const activeView = plugin.app.workspace.getActiveViewOfType(MarkdownView);
if (activeView?.file === plugin.targetFile) {
return;
}
const containerHeight = containerRef.current.offsetHeight;
const taskOffsetTop = firstUncompletedTaskRef.current.offsetTop;
const scrollToPosition = taskOffsetTop - containerHeight / 5;
@ -199,7 +195,7 @@ const TimetableViewComponent = forwardRef<
useEffect(() => {
performScroll();
}, [tasks]);
}, [plugin.targetFile]);
useEffect(() => {
updateBackgroundColors();