while을 이용한 미주번호 찾아가기

while 을 이용하여 미주번호를 찾아간 후, 미주번호 뒤에 점(.)을 입력하려 하는데, 무한 루프가 돌아가네요
다음 코드를 이용해 보았습니다.

function OnScriptMacro_script37()
{
    HAction.GetDefault("Goto", HParameterSet.HGotoE.HSet);
    with (HParameterSet.HGotoE) {
        HSet.SetItem("DialogResult", 32);
        SetSelectionIndex = 5;
    }

    while(HAction.Execute("Goto", HParameterSet.HGotoE.HSet)) {
        HAction.Run("MoveRight");
        SetTextFile(".", "UNICODE", "insertfile");
    }
}

function OnScriptMacro_script37()
{
    HAction.Run("MoveTopLevelBegin");
    A=GetPosBySet();
    AList = A.Item("List");
    APara = A.Item("Para");
    APos = A.Item("Pos");

    while (true) {
        HAction.GetDefault("Goto", HParameterSet.HGotoE.HSet);

        with (HParameterSet.HGotoE) {
            HSet.SetItem("DialogResult", 32);
            SetSelectionIndex = 5;
        }
        
        HAction.Execute("Goto", HParameterSet.HGotoE.HSet);
        B=GetPosBySet();
        BList = B.Item("List");
        BPara = B.Item("Para");
        BPos = B.Item("Pos");
        
        if(AList == BList && APara == BPara && APos == BPos) {
            break;
        }

        HAction.Run("MoveRight");
        SetTextFile(".", "UNICODE", "insertfile");
    }
}

위의 두 코드 모두 정상적으로 작동하지 않습니다.
어떻게 해야 할까요?

미주번호 찾아가기.hwp (18.5 KB)

안녕하세요
되돌이 검색이 되기 때문에 무한루프에 빠집니다.

올려주신 코드를 기반으로 예제를 만들어봤습니다. 처음 Pos를 기억하고 있다가 다시 들어오면 break를 하면 될 것 같습니다. 아래 예제 코드를 참고하시면 좋을 것 같습니다.
다른 문제가 있거나 궁금한 사항이 있으시면 다시 말씀 부탁드립니다.
감사합니다.

HAction.GetDefault("Goto", HParameterSet.HGotoE.HSet);
	with (HParameterSet.HGotoE)
	{
		HSet.SetItem("DialogResult", 32);
		SetSelectionIndex = 5;
	}
	
	firstPosList = -1;
	firstPosPara = -1;
	firstPosPos = -1;

	while(HAction.Execute("Goto", HParameterSet.HGotoE.HSet)) 
	{
	curPos=GetPosBySet();
	if(firstPosList  == -1 && firstPosPara == -1 && firstPosPos == -1)
	{
		
		firstPosList = curPos.Item("List");
		firstPosPara = curPos.Item("Para");
		firstPosPos = curPos.Item("Pos");
	}
	else if(firstPosList  ==curPos.Item("List") && firstPosPara ==curPos.Item("Para") && firstPosPos ==curPos.Item("Pos") ){
		break;
	}	
		HAction.Run("MoveRight");
		SetTextFile(".", "UNICODE", "insertfile");
	}
1개의 좋아요