Skip to content

Commit

Permalink
Add hacky way of adding plan items to note
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-lednev committed Aug 17, 2023
1 parent 5596d9e commit f069b75
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { parseTimestamp } from "../timestamp/timestamp";
import { timestampRegExp } from "../regexp";
import { isTopLevelListItem } from "../../obsidian-metadata-utils/src/list";
import { getTextAtPosition } from "../../obsidian-metadata-utils/src/position";
import { getDiffInMinutes, getMinutesSinceMidnightTo, minutesToMoment } from "../util/moment";
import {
getDiffInMinutes,
getMinutesSinceMidnightTo,
minutesToMoment,
} from "../util/moment";
import { DEFAULT_DURATION_MINUTES } from "../constants";
import { getTimeFromYOffset, roundToSnapStep } from "src/store/timeline-store";
import { getDailyNoteForToday } from "src/util/daily-notes";
Expand Down Expand Up @@ -40,6 +44,10 @@ export function parsePlanItems(
planHeadingContent,
);

if (!listItemsUnderPlan) {
return [];
}

const listItemsWithContent = getListItemContent(content, listItemsUnderPlan);

return listItemsWithContent
Expand Down
19 changes: 13 additions & 6 deletions src/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,25 @@ export async function appendToPlan(path: string, planItem: PlanItem) {

let result = replaceTimestamp(planItem, { ...planItem });

const headingMetadata = getHeadingByText(metadata, plannerHeading);
const headingLine = getHeadingByText(metadata, plannerHeading);

if (!headingMetadata) {
let line = editor.lastLine();

if (!headingLine) {
result = `${createPlannerHeading()}\n\n${result}`;
} else {
line = headingLine.position.start.line;
}

const listItems = getListItemsUnderHeading(metadata, plannerHeading);
const lastListItem = listItems[listItems.length - 1];

const line = lastListItem
? lastListItem.position.start.line
: editor.lastLine();
if (listItems?.length > 0) {
const lastListItem = listItems[listItems.length - 1];

line = lastListItem.position.start.line;
} else if (headingLine) {
result = `\n${result}`
}

const ch = editor.getLine(line).length;

Expand Down
2 changes: 1 addition & 1 deletion src/util/editor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Editor } from "obsidian";

export function selectText(editor: Editor, text: string) {
const startOffset = editor.getValue().indexOf(text);
const startOffset = editor.getValue().lastIndexOf(text);
const endOffset = startOffset + text.length;

editor.setSelection(
Expand Down

0 comments on commit f069b75

Please sign in to comment.