	include	ed.inc

	.code

_SkipWS	proc	near
	lea	bx,[di+size LineHeader]
	mov	cx,es:[di].LineLength
	sub	dx,dx
	jcxz	@@5
	mov	ax,920h
@@1:	cmp	es:[bx],al
	jne	@@2
	inc	dx
	inc	bx
	loop	@@1
	jmp	@@5
@@2:	cmp	es:[bx],ah
	jne	@@5
	push	cx
	mov	cx,ds:TabSize
	cmp	cx,1
	jg	@@3
	inc	dx
	jmp	@@4
@@3:	add	dx,cx
	push	dx
	mov	ax,dx
	sub	dx,dx
	div	cx
	pop	ax
	sub	ax,dx
	mov	dx,ax
@@4:	pop	cx
	mov	ax,920h
	inc	bx
	loop	@@1
@@5:	inc	dx
	mov	ds:CursorPos.X,dx
	dec	dx
	clc
	ret
_SkipWS	endp

	Entry	SkipWS
	Invoke	FindCurLine
	Invoke	UseCurPage
	mov	di,bx
	cmp	bx,dx
	je	@@1
	call	_SkipWS
	jmp	@@2
@@1:	stc
@@2:	Exit	SkipWS

	Entry	IndentBlock
	Invoke	BlockShown
	Invoke	SetEditDS
	jz	@@5
	mov	ax,ds:BlockBeg.Y
	mov	ds:CursorPos.Y,ax
@@1:	mov	ax,ds:CursorPos.Y
	cmp	ax,ds:BlockEnd.Y
	jb	@@2
	ja	@@4
	cmp	ds:BlockEnd.X,1
	jbe	@@4
@@2:	Invoke	SkipWS
	Invoke	SetEditDS
	jc	@@4
	jcxz	@@3
	or	ds:RedrawFlags,rfBelowCurLine
	mov	byte ptr ds:CParam,' '
	push	ds:BlockBeg.X
	Invoke	InsertNoOver
	Invoke	SetEditDS
	pop	ds:BlockBeg.X
@@3:	Invoke	PackLine
	Invoke	SetEditDS
	inc	ds:CursorPos.Y
	jnz	@@1
@@4:	Invoke	MoveToBlockBegRaw
	Invoke	CenterFixScreen
@@5:	Exit	IndentBlock

	Entry	OutdentBlock
	Invoke	BlockShown
	Invoke	SetEditDS
	jnz	@@1
	jmp	@@9
@@1:	mov	ax,ds:BlockBeg.Y
	mov	ds:CursorPos.Y,ax
@@2:	mov	ax,ds:CursorPos.Y
	cmp	ax,ds:BlockEnd.Y
	jb	@@4
	ja	@@3
	cmp	ds:BlockEnd.X,1
	ja	@@4
@@3:	jmp	@@8
@@4:	Invoke	SkipWS
	Invoke	UseCurPage
	jc	@@8
	jcxz	@@7
	test	dx,dx
	jz	@@7
	or	ds:RedrawFlags,rfBelowCurLine
	cmp	byte ptr es:[bx-1],9
	jne	@@6
	dec	dx
	mov	byte ptr es:[bx-1],' '
	mov	bx,di
	push	dx
	call	_SkipWS
	pop	ax
	sub	ax,dx
	mov	cx,ax
	jz	@@7
	jb	@@6
@@5:	mov	byte ptr ds:CParam,' '
	push	cx
	Invoke	InsertNoOver
	pop	cx
	loop	@@5
	jmp	@@7
@@6:	Invoke	FoolBS
@@7:	Invoke	PackLine
	Invoke	SetEditDS
	inc	ds:CursorPos.Y
	jz	@@8
	jmp	@@2
@@8:	Invoke	MoveToBlockBegRaw
	Invoke	CenterFixScreen
@@9:	Exit	OutdentBlock

	end
